(defun / (x y) (/ x y))
(defun 1+ (x) (+ x 1))
(defun 1- (x) (- x 1))
- (defun cons (x y ) (cons x y))
+ (defun cons (x y) (cons x y))
(defun car (x) (car x))
(defun cdr (x) (cdr x))
(if (null list)
'()
(cons (funcall func (car list))
- (mapcar func (cdr list))))))
+ (mapcar func (cdr list)))))
+
+ (defmacro push (x place)
+ `(setq ,place (cons ,x ,place))))
(defun !reduce (func list initial)
#+common-lisp
(progn
-
(defmacro while (condition &body body)
`(do ()
((not ,condition))
"){"
*newline*
(if rest-argument
- (concat "var " (lookup-variable rest-argument new-env)
- " = arguments.slice("
- (prin1-to-string (length required-arguments))
- ");"
+ (concat "var " (lookup-variable rest-argument new-env) ";" *newline*
+ "for (var i = arguments.length-1; i>="
+ (integer-to-string (length required-arguments))
+ "; i--)" *newline*
+ (lookup-variable rest-argument new-env) " = "
+ "{car: arguments[i], cdr: " (lookup-variable rest-argument new-env) "};"
*newline*)
"")
(concat (ls-compile-block (butlast body) new-env fenv)