anchor.diff:             :test 'string=) 
     "$v")
   
  +(defparameter *declared-vars* nil
  +  "This variable holds the javascript vars that need to be declared at
  +  each function scope level.")
  +
   (defun emit-var-declarations ()
  +  "Emit javascript function level vars."
     (when *declared-vars*
  -    (let ((*declared-vars* (copy-list (cl:sort *declared-vars* 'string<))))
  +    (let ((*declared-vars* (copy-list (cl:sort *declared-vars* #'cl:string<))))
         (emit-indented "var " (first *declared-vars*))
         (dolist (var (rest *declared-vars*))
           (emit ", " var))
  
positive.code:               (value (third v-p/p/value)))
            (when v-p
              (emit-indented-line p " = " value ";"))))
        (concat (if (equal "$v" fun-name)
                    (value)
                    (global-lookup-function fun-name))
                "("
  
negative.code:                                    (do* ((lambda-list lambda-list (rest lambda-list))
                                           (param (car lambda-list) (car lambda-list)))
                                          ((or (not lambda-list)
                                               (member param '(&optional &rest &key &aux
                                                               cl::&optional cl::&rest cl::&key cl::&aux)))
                                           lambda-list)
                                       (setf env (env-extend env param))
                                       (let ((var-name (env-emitted-name (env-lookup env param))))
                                         (pushnew var-name *declared-vars*
                                                  :test 'string=)
                                         (emit-indented-line var-name " = arguments[" n "];"))
                                       (incf n))))
                                (setf arity n)
                                ;; handle optional parameters
                                (when (member (car lambda-list) '(&optional cl::&optional))
                                  (setf arity-op '>=)
                                  (do* ((lambda-list (rest lambda-list) (rest lambda-list))
                                        (param (car lambda-list)
                                               (car lambda-list)))
                                       ((or (not lambda-list)
                                            (member param '(&rest &key &aux
                                                            cl::&rest cl::&key cl::&aux)))
                                        lambda-list)
                                    (let* ((param (if (listp param) (car param) param))
                                           (default (if (listp param) (cadr param) nil))
                                           (var-name (env-emitted-name (env-lookup env param))))
                                      (setf env (env-extend env param))
                                      (pushnew var-name *declared-vars*
                                               :test 'string=)
                                      (emit-indented-line var-name " = arguments.length > " n " ? arguments[" n "] : " (compile-expression default env) ";"))
                                    (incf n)))
                                (when (member (car lambda-list) '(&rest
                                                                  cl::&rest))
                                  (setf arity-op '>=)
                                  ;; a rest for sucks up all of the remaining arguments into a
                                  ;; list
                                  (assert (consp (cdr lambda-list)))
                                  (let* ((param (car (cdr lambda-list)))
                                         (var-name (env-emitted-name (env-lookup env param))))
                                    (pushnew var-name *declared-vars*
                                             :test 'string=)
                                    (setf env (env-extend env param))
                                    (emit-indented-line "var $n = " n ";")
                                    (emit-indented-line var-name " = " (compile-expression 'nil env) ";")
                                    (emit-indented-line "for($n = arguments.length-1; $n >= " n "; $n--) {")
                                    (with-indent
                                        (emit-indented-line var-name " = { type: \"cons\", car: arguments[$n], cdr: " var-name " };"))
                                    (emit-indented-line "}"))
                                  ;; advance the lambda list forward after "&rest args"
                                  (setf lambda-list (cddr lambda-list)))
                                ;; we'll handle keyword arguments later
                                #+nil(when (member (car lambda-list) '(&key
                                                                       cl::&key))
                                       ;; keyword args assume that from this point on the arguments
                                       ;; will be key/value pairs
                                       )))))
      (compile-statement `(assert (,arity-op (js-inline () "$v = arguments.length;") ,arity))
                         env)
      (emit compiled-params)
      env))
  