X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=test.lisp;h=a85dabaf9dae68350c902eb54fbc953e1099daca;hb=cde0e46ceeba0bf1eafcf43b13cd95a7eb14e6f7;hp=b5f04371ffceb0346a89061859c9550c4a93515d;hpb=2f34bc47948880d48086a4729e88317f50740a8a;p=jscl.git diff --git a/test.lisp b/test.lisp index b5f0437..a85daba 100644 --- a/test.lisp +++ b/test.lisp @@ -1,3 +1,57 @@ +;;; Library + +(eval-when-compile + (%compile-defmacro 'defmacro + (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))))) + + +;;; Tests + (lambda (x y) x) (debug "hola") @@ -21,15 +75,12 @@ (debug ((lambda (x) x) 9999)) +(debug #'f) + ;;; Macros (debug "---MACROS---") -(eval-when-compile - (%compile-defmacro 'defmacro - (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))) @@ -66,7 +117,6 @@ (debug (lambda (x y &rest z) z)) (debug (lambda (x y &rest z) x)) -;; (debug (foo)) ;; (eval-when-compile ;; (%compile-defmacro 'defun