diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-06-06 16:41:37 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-06-06 16:41:37 -0700 |
commit | 9fd3111ea9c08cb3a34989e9671fb5f46b3c4ed5 (patch) | |
tree | 7b2433289ec0adb0999d311e6a4226433de64f28 | |
parent | f79ae9ea548af8969db789dac4222b54641c922b (diff) | |
download | mu-9fd3111ea9c08cb3a34989e9671fb5f46b3c4ed5.tar.gz |
shell: more foundations from Lisp
-rw-r--r-- | shell/data.limg | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/shell/data.limg b/shell/data.limg index 092eef5c..b3c9ad2d 100644 --- a/shell/data.limg +++ b/shell/data.limg @@ -9,6 +9,11 @@ `((fn (,var) ,@body) ,val))]) (when . [(mac (when cond . body) `(if ,cond (do ,@body) ()))]) + (iflet . [(mac (iflet var expr then else) + `(let ,var ,expr + (if ,var ,then ,else)))]) + (aif . [(mac (aif expr then else) + `(iflet it ,expr ,then ,else))]) (list . [(def (list . args) # we should probably make a copy here args)]) @@ -21,6 +26,45 @@ () (cons (f (car xs)) (map1 f (cdr xs)))))]) + (compose . [(def (compose f g) + (fn args + (f (g args))))]) + (some . [(def (some f xs) + (if (no xs) + () + (if (f (car xs)) + xs + (some f (cdr xs)))))]) + (any . some) + (all . [(def (all f xs) + (if (no xs) + 1 + (if (f (car xs)) + (all f (cdr xs)) + ())))]) + (find . [(def (find x xs) + (if (no xs) + () + (if (= x (car xs)) + 1 + (find x (cdr xs)))))]) + (afn . [(mac (afn params . body) + `(let self () + (set self (fn ,params ,@body))))]) + (rem . [(def (rem f xs) + (if (no xs) + () + (let rest (rem f (cdr xs)) + (if (f (car xs)) + rest + (cons (car xs) rest)))))]) + (keep . [(def (keep f xs) + (if (no xs) + () + (let rest (keep f (cdr xs)) + (if (f (car xs)) + (cons (car xs) rest) + rest))))]) (++ . [(mac (++ var) `(set ,var (+ ,var 1)))]) (+= . [(mac (+= var inc) `(set ,var (+ ,var ,inc)))]) |