start using infix in data disk
Still some gaps to track down.
This commit is contained in:
parent
76ef912eb2
commit
f174695400
111
shell/data.limg
111
shell/data.limg
|
@ -25,11 +25,11 @@
|
|||
(len . [def (len l)
|
||||
if (no l)
|
||||
0
|
||||
(+ 1 (len (cdr l)))])
|
||||
(1 + (len (cdr l)))])
|
||||
(nth . [def (nth n xs)
|
||||
if (< n 1)
|
||||
if (n < 1)
|
||||
(car xs)
|
||||
(nth (- n 1) (cdr xs))])
|
||||
(nth n-1 (cdr xs))])
|
||||
(map1 . [def (map1 f xs)
|
||||
if (no xs)
|
||||
()
|
||||
|
@ -58,7 +58,7 @@
|
|||
(find . [def (find x xs)
|
||||
if (no xs)
|
||||
()
|
||||
if (= x (car xs))
|
||||
if (x = (car xs))
|
||||
1
|
||||
(find x (cdr xs))])
|
||||
(pair . [def (pair xs)
|
||||
|
@ -77,9 +77,9 @@
|
|||
(set self (fn ,params ,@body)))])
|
||||
(seq . [def (seq n)
|
||||
((afn (i)
|
||||
(if (> i n)
|
||||
(if (i > n)
|
||||
()
|
||||
(cons i (self (+ i 1)))))
|
||||
(cons i (self i+1))))
|
||||
1)])
|
||||
(each . [mac (each x xs . body)
|
||||
`(walk ,xs (fn (,x) ,@body))])
|
||||
|
@ -101,22 +101,22 @@
|
|||
if (f (car xs))
|
||||
(cons (car xs) rest)
|
||||
rest])
|
||||
(++ . [mac (++ var) `(set ,var (+ ,var 1))])
|
||||
(+= . [mac (+= var inc)
|
||||
`(set ,var (+ ,var ,inc))])
|
||||
(++ . [mac (++ var) `(set ,var (,var + 1))])
|
||||
(+= . [mac (var += inc)
|
||||
`(set ,var (,var + ,inc))])
|
||||
(for . [mac (for var init test update . body)
|
||||
`(let ,var ,init
|
||||
(while ,test
|
||||
,@body
|
||||
,update))])
|
||||
(hline1 . [def (hline1 screen y x xmax color)
|
||||
while (< x xmax)
|
||||
while (x < xmax)
|
||||
(pixel screen x y color)
|
||||
(++ x)])
|
||||
(vline1 . [def (vline1 screen x y ymax color)
|
||||
while (< y ymax)
|
||||
while (y < ymax)
|
||||
(pixel screen x y color)
|
||||
(++ y)])
|
||||
++ y])
|
||||
(hline . [def (hline scr y color)
|
||||
(hline1 scr y 0 (width scr) color)])
|
||||
(vline . [def (vline scr x color)
|
||||
|
@ -124,79 +124,76 @@
|
|||
(line . [def (line screen x0 y0 x1 y1 color)
|
||||
with (x x0
|
||||
y y0
|
||||
dx (abs (- x1 x0))
|
||||
dy (- 0 (abs (- y1 y0)))
|
||||
sx (sgn (- x1 x0))
|
||||
sy (sgn (- y1 y0)))
|
||||
let err (+ dx dy)
|
||||
while (not (and (= x x1)
|
||||
(= y y1)))
|
||||
dx (abs x1-x0)
|
||||
dy (0 - (abs y1-y0))
|
||||
sx (sgn x1-x0)
|
||||
sy (sgn y1-y0))
|
||||
let err dx+dy
|
||||
while (not (and (x = x1)
|
||||
(y = y1)))
|
||||
(pixel screen x y color)
|
||||
let e2 (* err 2)
|
||||
when (>= e2 dy)
|
||||
(+= x sx)
|
||||
when (<= e2 dx)
|
||||
(+= y sy)
|
||||
(+= err
|
||||
(+ (if (>= e2 dy)
|
||||
let e2 err*2
|
||||
when (e2 >= dy)
|
||||
x += sx
|
||||
when (e2 <= dx)
|
||||
y += sy
|
||||
err +=
|
||||
(+ (if (e2 >= dy)
|
||||
dy
|
||||
0)
|
||||
(if (<= e2 dx)
|
||||
(if (e2 <= dx)
|
||||
dx
|
||||
0)))])
|
||||
0))])
|
||||
(read_line . [def (read_line keyboard)
|
||||
ret str (stream)
|
||||
let c (key keyboard)
|
||||
while (not (or (= c 0) (= c 10)))
|
||||
while (not (or (c = 0) (c = 10)))
|
||||
(write str c)
|
||||
(set c (key keyboard))])
|
||||
(wait . [def (wait keyboard)
|
||||
while (= 0 (key keyboard))
|
||||
()])
|
||||
(sq . [def (sq n) (* n n)])
|
||||
(cube . [def (cube n) (* (* n n) n)])
|
||||
(sq . [def (sq n) (n * n)])
|
||||
(cube . [def (cube n) (n * n * n)])
|
||||
(fill_rect . [def (fill_rect screen x1 y1 x2 y2 color)
|
||||
for y y1 (< y y2) (++ y)
|
||||
for y y1 (y < y2) (++ y)
|
||||
(hline1 screen y x1 x2 color)])
|
||||
(circle . [def (circle scr cx cy r clr)
|
||||
with (x (- 0 r)
|
||||
with (x (0 - r)
|
||||
y 0
|
||||
err (- 2 (* 2 r))
|
||||
err (2 - (* 2 r))
|
||||
continue 1)
|
||||
while continue
|
||||
(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)
|
||||
(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)
|
||||
(set r err)
|
||||
when (<= r y)
|
||||
(++ y)
|
||||
(+= err
|
||||
(+ 1 (* 2 y)))
|
||||
when (or (> r x) (> err y))
|
||||
(++ x)
|
||||
(+= err
|
||||
(+ 1 (* 2 x)))
|
||||
(set continue (< x 0))])
|
||||
when (r <= y)
|
||||
++ y
|
||||
err += (1 + (2 * y))
|
||||
when (or (r > x) (err > y))
|
||||
++ x
|
||||
err += (+ 1 (* 2 x))
|
||||
set continue (x < 0)])
|
||||
(ring . [def (ring screen cx cy r0 w clr)
|
||||
for r r0 (< r (+ r0 w)) (++ r)
|
||||
for r r0 (r < (r0 + w)) (++ r)
|
||||
(circle screen cx cy r clr)])
|
||||
(Greys . [define Greys
|
||||
(map1 (fn(n) (+ n 15))
|
||||
(map1 (fn(n) (n + 15))
|
||||
(seq 16))])
|
||||
(Pinks . [define Pinks '(84 85 59 60 61
|
||||
13 36 37 5 108)])
|
||||
(palette . [def (palette p i)
|
||||
(nth (% i (len p)) p)])
|
||||
(nth (i % (len p)) p)])
|
||||
(pat . [def (pat screen)
|
||||
(let w (width screen)
|
||||
(let h (height screen)
|
||||
(for y 0 (< y h) (++ y)
|
||||
(for x 0 (< x w) (++ x)
|
||||
(pixel screen x y
|
||||
(* x y))))))])
|
||||
with (w (width screen)
|
||||
h (height screen))
|
||||
for y 0 (y < h) (++ y)
|
||||
for x 0 (x < w) (++ x)
|
||||
(pixel screen x y x*y)])
|
||||
(main . [def (main screen keyboard)
|
||||
(pat screen)])
|
||||
))
|
||||
(sandbox . [(pat screen)])
|
||||
(sandbox . [circle screen 35 35 14 3])
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue