about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-23 00:01:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-23 00:03:07 -0700
commitf174695400fcbaacf9ef6a66a72e3f71ff6bf302 (patch)
tree7bf626cda6a70993a1637b9f5b22bb0a0f5d497e /shell
parent76ef912eb25cf6eccac43253ad1184d6fd502426 (diff)
downloadmu-f174695400fcbaacf9ef6a66a72e3f71ff6bf302.tar.gz
start using infix in data disk
Still some gaps to track down.
Diffstat (limited to 'shell')
-rw-r--r--shell/data.limg111
1 files changed, 54 insertions, 57 deletions
diff --git a/shell/data.limg b/shell/data.limg
index 5b8a0a0d..03366720 100644
--- a/shell/data.limg
+++ b/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])
 )