diff options
-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)))]) |