- (lambda (name args &rest body)
- (list 'eval-when-compile
- (list '%compile-defmacro (list 'quote name)
- (list* 'lambda args body))))))
-
-(defmacro incf (x)
- (list 'setq x (list '+ 1 x)))
-
-(eval-when-compile
- (%compile-defvar 'x))
-
-(setq x 10)
-(incf x)
-(debug x)
-
-;;; Conses
-(debug (cons 1 2))
-(debug (car (cons 1 2)))
-(debug (cdr (cons 1 2)))
-
-(setq x '(1 . 2))
-(debug x)
-(debug (eq x x))
-(debug (eq '(1 . 2) '(1 . 2)))
-
-;;; Symbols
-(debug (symbol-name 'foo))
-(debug (symbol-name 'foo-bar))
-
-(debug (progn 1 2 3 123))
-
-(debug (let ((x 99999))
- (incf x)))
-
-;;; &rest lambda-list
-
-(debug (lambda (&rest x) x))
-(debug (lambda (x y &rest z) z))
-(debug (lambda (x y &rest z) x))
-
-
-(progn
- (eval-when-compile
- (%compile-defun 'f))
- (fsetq f (lambda (x) (* x x))))
-
-(debug (f 33))
-
-;; (debug (foo))
-
-;; (eval-when-compile
-;; (%compile-defmacro 'defun
-;; (lambda (name args &rest body)
-;; (list 'eval-when-compile
-;; (list 'compile-defun)
-;; (list 'fsetq (list 'lambda args (list 'progn body)))))))
+ (lambda (name args &rest body)
+ `(eval-when-compile
+ (%compile-defmacro ',name (lambda ,args ,@body))))))
+
+(defmacro defvar (name value)
+ `(progn
+ (eval-when-compile
+ (%compile-defvar ',name))
+ (setq ,name ,value)))
+
+(defmacro defun (name args &rest body)
+ `(progn
+ (eval-when-compile
+ (%compile-defun ',name))
+ (fsetq ,name (lambda ,args ,@body))))
+
+(defun = (x y) (= x y))
+(defun + (x y) (+ x y))
+(defun - (x y) (- x y))
+(defun * (x y) (* x y))
+(defun / (x y) (/ x y))
+(defun 1+ (x) (+ x 1))
+(defun 1- (x) (- x 1))
+(defun cons (x y ) (cons x y))
+(defun car (x) (car x))
+(defun cdr (x) (cdr x))
+
+(defun append (list1 list2)
+ (if (null list1)
+ list2
+ (cons (car list1)
+ (append (cdr list1) list2))))
+
+(defun reverse-aux (list acc)
+ (if (null list)
+ acc
+ (reverse-aux (cdr list) (cons (car list) acc))))
+
+(defun reverse (list)
+ (reverse-aux list '()))
+
+(defun mapcar (func list)
+ (if (null list)
+ '()
+ (cons (funcall func (car list))
+ (mapcar func (cdr list)))))
+
+(defmacro push (x place)
+ `(setq ,place (cons ,x ,place)))
+
+(defvar *package* (new))
+
+(defun intern (name)
+ (let ((s (get *package* name)))
+ (if s
+ s
+ (set *package* name (make-symbol name)))))
+
+(defun find-symbol (name)
+ (get *package* name))