2021-04-24 04:36:48 +00:00
|
|
|
(
|
|
|
|
(globals . (
|
2021-06-21 05:53:55 +00:00
|
|
|
(mac . [define mac
|
|
|
|
(litmac litfn () ((m . params) . body)
|
|
|
|
`(define ,m
|
|
|
|
(litmac litfn () ,params ,@body)))])
|
2021-06-21 04:29:33 +00:00
|
|
|
(def . [mac (def (name . params) . body)
|
|
|
|
`(define ,name (fn ,params ,@body))])
|
|
|
|
(do . [mac (do . body)
|
|
|
|
`((fn () ,@body))])
|
2021-06-23 23:24:56 +00:00
|
|
|
(let . [mac (let var val . body)
|
|
|
|
`((fn (,var) ,@body) ,val)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(when . [mac (when cond . body)
|
|
|
|
`(if ,cond (do ,@body) ())])
|
|
|
|
(iflet . [mac (iflet var expr then else)
|
2021-06-06 23:41:37 +00:00
|
|
|
`(let ,var ,expr
|
2021-06-21 04:29:33 +00:00
|
|
|
(if ,var ,then ,else))])
|
|
|
|
(aif . [mac (aif expr then else)
|
|
|
|
`(iflet it ,expr ,then ,else)])
|
|
|
|
(list . [def (list . args)
|
2021-06-06 23:40:35 +00:00
|
|
|
# we should probably make a copy here
|
2021-06-21 04:29:33 +00:00
|
|
|
args])
|
2021-06-21 04:35:02 +00:00
|
|
|
(ret . [mac (ret var val . body)
|
|
|
|
`(let ,var ,val ,@body ,var)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(len . [def (len l)
|
|
|
|
if (no l)
|
2021-06-06 19:55:06 +00:00
|
|
|
0
|
2021-06-23 07:01:55 +00:00
|
|
|
(1 + (len (cdr l)))])
|
2021-06-21 04:29:33 +00:00
|
|
|
(nth . [def (nth n xs)
|
2021-06-23 07:01:55 +00:00
|
|
|
if (n < 1)
|
2021-06-07 05:14:24 +00:00
|
|
|
(car xs)
|
2021-06-23 07:01:55 +00:00
|
|
|
(nth n-1 (cdr xs))])
|
2021-06-21 04:29:33 +00:00
|
|
|
(map1 . [def (map1 f xs)
|
|
|
|
if (no xs)
|
2021-06-06 19:55:06 +00:00
|
|
|
()
|
|
|
|
(cons (f (car xs))
|
2021-06-21 04:29:33 +00:00
|
|
|
(map1 f (cdr xs)))])
|
|
|
|
(compose . [def (compose f g)
|
2021-06-06 23:41:37 +00:00
|
|
|
(fn args
|
2021-06-21 05:24:03 +00:00
|
|
|
(f (apply g args)))])
|
2021-06-21 05:57:36 +00:00
|
|
|
(caar . [define caar (compose car car)])
|
|
|
|
(cadr . [define cadr (compose car cdr)])
|
|
|
|
(cddr . [define cddr (compose cdr cdr)])
|
|
|
|
(cdar . [define cdar (compose cdr car)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(some . [def (some f xs)
|
|
|
|
if (no xs)
|
2021-06-06 23:41:37 +00:00
|
|
|
()
|
2021-06-21 04:29:33 +00:00
|
|
|
if (f (car xs))
|
2021-06-06 23:41:37 +00:00
|
|
|
xs
|
2021-06-21 04:29:33 +00:00
|
|
|
(some f (cdr xs))])
|
2021-06-21 05:45:13 +00:00
|
|
|
(any . [define any some])
|
2021-06-21 04:29:33 +00:00
|
|
|
(all . [def (all f xs)
|
|
|
|
if (no xs)
|
2021-06-06 23:41:37 +00:00
|
|
|
1
|
2021-06-21 04:29:33 +00:00
|
|
|
if (f (car xs))
|
2021-06-06 23:41:37 +00:00
|
|
|
(all f (cdr xs))
|
2021-06-21 04:29:33 +00:00
|
|
|
()])
|
|
|
|
(find . [def (find x xs)
|
|
|
|
if (no xs)
|
2021-06-06 23:41:37 +00:00
|
|
|
()
|
2021-06-23 07:01:55 +00:00
|
|
|
if (x = (car xs))
|
2021-06-06 23:41:37 +00:00
|
|
|
1
|
2021-06-21 04:29:33 +00:00
|
|
|
(find x (cdr xs))])
|
2021-06-21 05:24:03 +00:00
|
|
|
(pair . [def (pair xs)
|
|
|
|
if (no xs)
|
|
|
|
()
|
|
|
|
if (no (cdr xs))
|
|
|
|
(list (list (car xs)))
|
2021-06-21 05:57:36 +00:00
|
|
|
(cons (list (car xs) (cadr xs))
|
|
|
|
(pair (cddr xs)))])
|
2021-06-21 06:09:50 +00:00
|
|
|
(with . [mac (with bindings . body)
|
|
|
|
`((fn ,(map1 car (pair bindings))
|
2021-06-21 05:24:03 +00:00
|
|
|
,@body)
|
2021-06-21 06:09:50 +00:00
|
|
|
,@(map1 cadr (pair bindings)))])
|
2021-06-21 04:29:33 +00:00
|
|
|
(afn . [mac (afn params . body)
|
2021-06-06 23:41:37 +00:00
|
|
|
`(let self ()
|
2021-06-21 04:29:33 +00:00
|
|
|
(set self (fn ,params ,@body)))])
|
|
|
|
(seq . [def (seq n)
|
2021-06-07 02:03:41 +00:00
|
|
|
((afn (i)
|
2021-06-23 07:01:55 +00:00
|
|
|
(if (i > n)
|
2021-06-07 02:03:41 +00:00
|
|
|
()
|
2021-06-23 07:01:55 +00:00
|
|
|
(cons i (self i+1))))
|
2021-06-21 04:29:33 +00:00
|
|
|
1)])
|
|
|
|
(each . [mac (each x xs . body)
|
|
|
|
`(walk ,xs (fn (,x) ,@body))])
|
|
|
|
(walk . [def (walk xs f)
|
|
|
|
when xs
|
2021-06-07 02:03:41 +00:00
|
|
|
(f (car xs))
|
2021-06-21 04:29:33 +00:00
|
|
|
(walk (cdr xs) f)])
|
|
|
|
(rem . [def (rem f xs)
|
|
|
|
if (no xs)
|
2021-06-06 23:41:37 +00:00
|
|
|
()
|
2021-06-21 04:29:33 +00:00
|
|
|
let rest (rem f (cdr xs))
|
|
|
|
if (f (car xs))
|
2021-06-06 23:41:37 +00:00
|
|
|
rest
|
2021-06-21 04:29:33 +00:00
|
|
|
(cons (car xs) rest)])
|
|
|
|
(keep . [def (keep f xs)
|
|
|
|
if (no xs)
|
2021-06-06 23:41:37 +00:00
|
|
|
()
|
2021-06-21 04:29:33 +00:00
|
|
|
let rest (keep f (cdr xs))
|
|
|
|
if (f (car xs))
|
2021-06-06 23:41:37 +00:00
|
|
|
(cons (car xs) rest)
|
2021-06-21 04:29:33 +00:00
|
|
|
rest])
|
2021-07-03 23:28:15 +00:00
|
|
|
(alist? . [def (alist? x)
|
|
|
|
(and (cons? x)
|
|
|
|
(cons? (car x)))])
|
|
|
|
(assoc . [def (assoc alist key)
|
|
|
|
if (no alist)
|
|
|
|
()
|
|
|
|
if (key = (caar alist))
|
|
|
|
(car alist)
|
|
|
|
(assoc (cdr alist) key)])
|
|
|
|
(get . [def (get alist key)
|
|
|
|
aif (assoc alist key)
|
|
|
|
(cdr it)
|
|
|
|
()])
|
2021-06-23 07:01:55 +00:00
|
|
|
(++ . [mac (++ var) `(set ,var (,var + 1))])
|
|
|
|
(+= . [mac (var += inc)
|
|
|
|
`(set ,var (,var + ,inc))])
|
2021-06-21 04:29:33 +00:00
|
|
|
(for . [mac (for var init test update . body)
|
2021-06-06 00:49:03 +00:00
|
|
|
`(let ,var ,init
|
|
|
|
(while ,test
|
|
|
|
,@body
|
2021-06-21 04:29:33 +00:00
|
|
|
,update))])
|
|
|
|
(hline1 . [def (hline1 screen y x xmax color)
|
2021-06-23 07:01:55 +00:00
|
|
|
while (x < xmax)
|
2021-05-07 17:14:51 +00:00
|
|
|
(pixel screen x y color)
|
2021-06-23 07:59:14 +00:00
|
|
|
++x])
|
2021-06-21 04:29:33 +00:00
|
|
|
(vline1 . [def (vline1 screen x y ymax color)
|
2021-06-23 07:01:55 +00:00
|
|
|
while (y < ymax)
|
2021-05-07 17:14:51 +00:00
|
|
|
(pixel screen x y color)
|
2021-06-23 07:59:14 +00:00
|
|
|
++y])
|
2021-06-21 05:53:55 +00:00
|
|
|
(hline . [def (hline scr y color)
|
|
|
|
(hline1 scr y 0 (width scr) color)])
|
|
|
|
(vline . [def (vline scr x color)
|
|
|
|
(vline1 scr x 0 (height scr) color)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(read_line . [def (read_line keyboard)
|
2021-06-21 04:35:02 +00:00
|
|
|
ret str (stream)
|
|
|
|
let c (key keyboard)
|
2021-06-23 07:01:55 +00:00
|
|
|
while (not (or (c = 0) (c = 10)))
|
2021-06-21 04:35:02 +00:00
|
|
|
(write str c)
|
|
|
|
(set c (key keyboard))])
|
2021-06-21 04:29:33 +00:00
|
|
|
(wait . [def (wait keyboard)
|
|
|
|
while (= 0 (key keyboard))
|
|
|
|
()])
|
2021-06-23 07:01:55 +00:00
|
|
|
(sq . [def (sq n) (n * n)])
|
|
|
|
(cube . [def (cube n) (n * n * n)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(fill_rect . [def (fill_rect screen x1 y1 x2 y2 color)
|
2021-06-23 07:59:14 +00:00
|
|
|
for y y1 (y < y2) ++y
|
2021-06-21 04:29:33 +00:00
|
|
|
(hline1 screen y x1 x2 color)])
|
2021-06-21 05:53:55 +00:00
|
|
|
(circle . [def (circle scr cx cy r clr)
|
2021-06-23 07:01:55 +00:00
|
|
|
with (x (0 - r)
|
2021-06-21 05:33:05 +00:00
|
|
|
y 0
|
2021-06-24 16:18:59 +00:00
|
|
|
err (2 - 2*r)
|
2021-06-24 21:33:22 +00:00
|
|
|
continue? 1)
|
|
|
|
while continue?
|
2021-06-23 07:01:55 +00:00
|
|
|
(pixel scr cx-x cy+y clr)
|
|
|
|
(pixel scr cx-y cy-x clr)
|
|
|
|
(pixel scr cx+x cy-y clr)
|
|
|
|
(pixel scr cx+y cy+x clr)
|
2021-06-21 05:33:05 +00:00
|
|
|
(set r err)
|
2021-06-23 07:01:55 +00:00
|
|
|
when (r <= y)
|
2021-06-23 07:59:14 +00:00
|
|
|
++y
|
2021-06-23 18:05:57 +00:00
|
|
|
err += (2*y + 1)
|
2021-06-23 07:01:55 +00:00
|
|
|
when (or (r > x) (err > y))
|
2021-06-23 07:59:14 +00:00
|
|
|
++x
|
2021-06-23 18:05:57 +00:00
|
|
|
err += (2*x + 1)
|
2021-06-24 21:33:22 +00:00
|
|
|
set continue? (x < 0)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(ring . [def (ring screen cx cy r0 w clr)
|
2021-06-23 18:05:57 +00:00
|
|
|
for r r0 (r < r0+w) ++r
|
2021-06-21 04:29:33 +00:00
|
|
|
(circle screen cx cy r clr)])
|
|
|
|
(Greys . [define Greys
|
2021-06-23 18:05:57 +00:00
|
|
|
(map1 (fn(n) n+15)
|
2021-06-21 04:29:33 +00:00
|
|
|
(seq 16))])
|
|
|
|
(Pinks . [define Pinks '(84 85 59 60 61
|
2021-06-21 05:53:55 +00:00
|
|
|
13 36 37 5 108)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(palette . [def (palette p i)
|
2021-06-23 07:01:55 +00:00
|
|
|
(nth (i % (len p)) p)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(pat . [def (pat screen)
|
2021-06-23 07:01:55 +00:00
|
|
|
with (w (width screen)
|
|
|
|
h (height screen))
|
2021-06-23 07:59:14 +00:00
|
|
|
for y 0 (y < h) ++y
|
|
|
|
for x 0 (x < w) ++x
|
2021-06-23 07:01:55 +00:00
|
|
|
(pixel screen x y x*y)])
|
2021-06-21 04:29:33 +00:00
|
|
|
(main . [def (main screen keyboard)
|
|
|
|
(pat screen)])
|
2021-04-24 04:36:48 +00:00
|
|
|
))
|
2021-06-23 07:01:55 +00:00
|
|
|
(sandbox . [circle screen 35 35 14 3])
|
2021-04-24 04:36:48 +00:00
|
|
|
)
|