2008-04-27 23:12:52 -04:00
|
|
|
! Copyright (C) 2008 James Cash
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-05-26 15:48:22 -04:00
|
|
|
USING: lisp lisp.parser tools.test sequences math kernel parser arrays ;
|
2008-04-27 23:12:52 -04:00
|
|
|
|
2008-04-29 23:10:47 -04:00
|
|
|
IN: lisp.test
|
|
|
|
|
2008-05-22 18:38:51 -04:00
|
|
|
[
|
|
|
|
init-env
|
|
|
|
|
2008-06-05 18:14:43 -04:00
|
|
|
[ f ] "#f" lisp-define
|
|
|
|
[ t ] "#t" lisp-define
|
2008-05-22 18:38:51 -04:00
|
|
|
|
2008-05-26 15:48:22 -04:00
|
|
|
"+" "math" "+" define-primitive
|
|
|
|
"-" "math" "-" define-primitive
|
|
|
|
|
2008-05-22 18:38:51 -04:00
|
|
|
{ 5 } [
|
|
|
|
[ 2 3 ] "+" <lisp-symbol> funcall
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ 8.3 } [
|
|
|
|
[ 10.4 2.1 ] "-" <lisp-symbol> funcall
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ 3 } [
|
2008-05-26 15:48:22 -04:00
|
|
|
"((lambda (x y) (+ x y)) 1 2)" lisp-eval
|
2008-05-22 18:38:51 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ 42 } [
|
2008-05-26 15:48:22 -04:00
|
|
|
"((lambda (x y z) (+ x (- y z))) 40 3 1)" lisp-eval
|
2008-05-22 18:38:51 -04:00
|
|
|
] unit-test
|
|
|
|
|
2008-06-05 16:28:24 -04:00
|
|
|
{ T{ lisp-symbol f "if" } } [
|
|
|
|
"(defmacro if (pred tr fl) (quasiquote (cond ((unquote pred) (unquote tr)) (#t (unquote fl)))))" lisp-eval
|
|
|
|
] unit-test
|
|
|
|
|
2008-06-05 18:14:43 -04:00
|
|
|
{ t } [
|
|
|
|
T{ lisp-symbol f "if" } lisp-macro?
|
|
|
|
] unit-test
|
|
|
|
|
2008-05-22 18:38:51 -04:00
|
|
|
{ 1 } [
|
2008-05-26 15:48:22 -04:00
|
|
|
"(if #t 1 2)" lisp-eval
|
2008-05-22 18:38:51 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ "b" } [
|
2008-05-26 15:48:22 -04:00
|
|
|
"(cond (#f \"a\") (#t \"b\"))" lisp-eval
|
2008-05-22 18:38:51 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ 5 } [
|
2008-05-26 15:48:22 -04:00
|
|
|
"(begin (+ 1 4))" lisp-eval
|
2008-05-22 18:38:51 -04:00
|
|
|
] unit-test
|
|
|
|
|
|
|
|
{ 3 } [
|
2008-05-26 15:48:22 -04:00
|
|
|
"((lambda (x) (if x (begin (+ 1 2)) (- 3 5))) #t)" lisp-eval
|
|
|
|
] unit-test
|
|
|
|
|
2008-05-26 17:02:23 -04:00
|
|
|
] with-interactive-vocabs
|