1 USING: lazy-lists io strings sequences math namespaces kernel ;
4 : lambda-core ( -- expr-string-array )
7 ":SUCC (num.(one.(zero.(one((num one) zero)))))"
10 0 lfrom 100 swap ltake list>array
12 [ ":" , dup 1 + number>string , " (SUCC " , number>string ,
13 ")" , ] { } make concat
16 0 lfrom 26 swap ltake list>array
18 [ ":" , 65 + dup ch>string , " " , number>string , ] { } make concat
25 ":AND (p.(q.((p q) FALSE)))"
26 ":OR (p.(q.((p TRUE) q)))"
27 ":ISZERO (num.((num (pred. FALSE)) TRUE))"
28 ":ADD (num.(other.((num SUCC) other)))"
29 ":MULT (num.(other.((num (ADD other)) 0)))"
30 ":PRED (n.(f.(x.(((n (g.(h.(h(g f))))) (u. x)) (u.u)))))"
31 ":SUBFROM (num.(other.((num PRED) other)))"
32 ":EQUAL (num.(other.((AND (ISZERO ((SUBFROM num) other))) (ISZERO ((SUBFROM other) num)))))"
33 ":FACT (fact.(num.(((ISZERO num) 1) ((MULT num) (fact (PRED num))))))"
34 ":YCOMBINATOR (func.((y. (func (y y)))(y. (func (y y)))))"
35 ":FACTORIAL (YCOMBINATOR FACT)"
36 ":CONS (car.(cdr.(which.((which car) cdr))))"
37 ":CAR (cons.(cons TRUE))"
38 ":CDR (cons.(cons FALSE))"
39 ":PCONS (pcons.(num.(cons.(((ISZERO num) (PRINTSPECIAL LF)) ((PRINTCHAR (CAR cons)) ((pcons (PRED num)) (CDR cons)))))))"
40 ":PRINTCONS (YCOMBINATOR PCONS)"
41 ":NUMTOCHAR (num. ((ADD 48) num))"
42 ":PRINTNUM (num.(PRINTCHAR (NUMTOCHAR num)))"
43 ":PRINTCHAR (char.([PRINTCHAR] (ALIENNUM char)))"
44 ":PRINTSPECIAL (special.([PRINTCHAR] (ALIENNUM special)))"
45 ":ALIEN0 alienbaseonenum"
46 ":ALIENNUM (num.((num [ALIENSUCC]) ALIEN0))"
47 ":HELLOCONS ((CONS H) ((CONS E) ((CONS Y) ((CONS 0) nil))))"
48 ":HELLO ((PRINTCONS 3) HELLOCONS)"
49 "(([HELLO] nil) ([INFO] nil))"
52 : print-return ( -- node )
53 write "(nil.nil)" lambda-parse second ;
55 : HELLO ( node -- node )
56 drop "\nHello and Welcome to Lambda!\n" print-return ;
58 : INFO ( node -- node )
59 drop "Type HELLO and wait 10 seconds to see me flex my io muscles.\n" print-return ;
61 : ALIENSUCC ( node -- node )
62 var-node-name "a" append <var-node> ;
64 : ALIENPRED ( node -- node )
65 var-node-name dup length 1 - swap remove-nth <var-node> ;
67 : ALIENISZERO ( node -- node )
70 : PRINTCHAR ( node -- node )
71 #! takes a base one num and prints its char equivalent
72 var-node-name length "alienbaseonenum" length - ch>string print-return ;
74 : READCHAR ( node -- node )
75 #! reads one character of input and stores it as a base one num
76 "alienbaseonenum" read1 [ "a" append ] times <var-node> ;