-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo
executable file
·203 lines (139 loc) · 3.96 KB
/
demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/bash
# This simply pipes the lisp code into YALL
# If you want to use vim or any other text editor simply end the file
# with .scm or set your editor to a some sort of scheme file type
# supporting mode
# cd to what ever path this demo is being ran from
cd "$(dirname "$0")"
cat << EOF | ./lisp
(define short-sleep 4)
(define mid-sleep 5)
(define long-sleep 7)
(print (quote (Hello)))
(sleep short-sleep)
(print (quote (Welcome a demo of YALL a symbolic programming language)))
(sleep short-sleep)
(print (quote (YALL is a simple scheme like language written in C++)))
(sleep long-sleep)
(print (quote (So what can YALL do)))
(sleep mid-sleep)
;; Lists
(print (quote (You can create lists useing the LIST function like so (in lower case))))
(sleep short-sleep)
(print (quote (list 1 2 3)))
(print (quote (Will evaluate to)))
(sleep short-sleep)
(print (list 1 2 3))
(sleep mid-sleep)
(print (quote (you can access these elements using useing the CAR and CDR functions)))
(sleep short-sleep)
(print (quote (car (list 1 2 3))))
(print (quote (will result in)))
(sleep short-sleep)
(print
(car (list 1 2 3)))
(sleep short-sleep)
(print (quote (and)))
(print
(quote (cdr (list 1 2 3))))
(print (quote (will result in)))
(sleep short-sleep)
(print
(cdr (list 1 2 3)))
(sleep mid-sleep)
;; Consing
(print (quote
(Cons cells can be created using the cons function and the quote keyword)))
(print (cons 1 2))
(print (cons (quote a) (quote b)))
(print (cons (quote a)
(cons 1 (quote b))))
(print (cons (cons (quote a) (quote hello))
(cons 1 (quote b))))
(sleep short-sleep)
(print (quote (1 . 2)))
(print (quote (a . b)))
(print (quote (a . (1 . b))))
(print (quote ((a . hello) . (1 . b))))
(quote (a . (b . (c . (quote ())))))
(sleep short-sleep)
(print (quote (To save you some time the rest of this will
just evaluate and print so you do not have to wait
any longer)))
(sleep long-sleep)
;; Proposal based demo
(list (quote a) (quote b) (quote c))
(print (quote (+ 1 2)))
(print (+ 1 2))
(print (quote (cons 1 2)))
(print (cons 1 2))
(print (quote (quote (1 . 2))))
(print (quote (1 . 2)))
(print (quote (quote a)))
(print (quote a))
(print (quote (car (cons 1 2))))
(print (car (cons 1 2)))
(print (quote (cdr (cons 1 2))))
(print (cdr (cons 1 2)))
(print (quote (define x 1)))
(print (define x 1))
(print (quote (+ x 1)))
(print (+ x 1))
(print (quote (define y 10)))
(print (define y 10))
(print (quote (+ y 1)))
(print (+ y 1))
(print (quote (let ((x 1)
(y 9))
(+ x y))))
(print (let ((x 1)
(y 9))
(+ x y)))
(print (quote (let ((x 1)
(y 9))
(let ((x 5))
(+ x y)))))
(print (let ((x 1)
(y 9))
(let ((x 5))
(+ x y))))
(print (quote (lambda (x) (+ 9 x))))
(print (lambda (x) (+ 9 x)))
(print (quote ((lambda (x) (+ 9 x)) 2)))
(print ((lambda (x) (+ 9 x)) 2))
(print (quote (define adder (lambda (x) (+ 9 x)))))
(print (quote (adder 2)))
(print (define adder (lambda (x) (+ 9 x))))
(print (adder 2))
(print (quote (let ((adder (lambda (x) (+ 9 x))))
(adder 2))))
(print (let ((adder (lambda (x) (+ 9 x))))
(adder 2)))
(print (quote (define x (let ((x 1))
(lambda (y)
(+ x y))))))
(print (define x (let ((x 1))
(lambda (y)
(+ x y)))))
(print (quote (x 2)))
(print (x 2))
(print (quote (if (= 2 1)
(+ 1 2)
(- 1 2))))
(print (if (= 2 1)
(+ 1 2)
(- 1 2)))
(print (quote (eq 1 1)))
(print (eq 1 1))
(print (quote (eq (quote a) (quote a))))
(print (eq (quote a) (quote a)))
(print (quote (eq (quote a) (quote b))))
(print (eq (quote a) (quote b)))
(print (quote (eq (quote a) 1)))
(print (eq (quote a) 1))
(print (quote (eq #t #t)))
(print (eq #t #t))
(print (quote (eq #t #f)))
(print (eq #t #f))
(quote (This will be printed since it is the last evaluated form))
EOF