X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=test.lisp;h=f63710a8fa9390de2527f093b27a25a75a28d7b1;hb=b555a69d351b6be0ed61343d79a80771957a7413;hp=4b6e015df4eec0ed6b5f4d1c2c5ff2e4bd374e53;hpb=be0e560b524c25392d87b2226571052adf3fd5ae;p=jscl.git diff --git a/test.lisp b/test.lisp index 4b6e015..f63710a 100644 --- a/test.lisp +++ b/test.lisp @@ -1,5 +1,36 @@ -(lambda (x y) - x) +;;; Library + +(eval-when-compile + (%compile-defmacro 'defmacro + (lambda (name args &rest body) + `(eval-when-compile + (%compile-defmacro ',name (lambda ,args ,@body)))))) + +(defmacro defun (name args &rest body) + `(progn + (eval-when-compile + (%compile-defun ',name)) + (fsetq ,name (lambda ,args ,@body)))) + +(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 '())) + +(debug (reverse '(1 2 3 4))) + +;;; Tests + +(lambda (x y) x) (debug "hola") (debug '(1 2 3 4)) @@ -20,15 +51,14 @@ (fsetq f (lambda (x) (+ x 10))) (debug (f 20)) +(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))) @@ -45,17 +75,26 @@ (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)) -;; (debug (foo)) ;; (eval-when-compile ;; (%compile-defmacro 'defun