diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-10 22:00:17 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-12-11 01:37:50 +0200 |
| commit | f522e39756ae0aef5e49585fc735c475cf3ff9e4 (patch) | |
| tree | 90a8fe239b064c5b1b20fe2ad2fbe7f7e792bff9 /core | |
| parent | 37e251578181213e49ba08d3de39f0b8b4f77427 (diff) | |
Refactor builtins, add new ones
Diffstat (limited to 'core')
| -rw-r--r-- | core/common.milch | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/core/common.milch b/core/common.milch index 2dc6698..a81a4ef 100644 --- a/core/common.milch +++ b/core/common.milch @@ -91,7 +91,7 @@ (let take (\[n xs] (match n 0 [] - otherwise (prepend (head xs) (take (- n 1) (tail xs)))))) + otherwise (cons (head xs) (take (- n 1) (tail xs)))))) (let drop (\[n xs] (match n @@ -102,7 +102,7 @@ (let map (\[f lst] (match lst [] [] - otherwise (prepend (f (head lst)) (map f (tail lst)))))) + otherwise (cons (f (head lst)) (map f (tail lst)))))) ; foldr :: (a -> b -> b) -> b -> [a] -> b (let foldr (\[f accumulator lst] @@ -116,14 +116,14 @@ [] [] otherwise (match (pred (head lst)) true - (prepend (head lst) (filter pred (tail lst))) + (cons (head lst) (filter pred (tail lst))) false (filter pred (tail lst)))))) (let _reverse (\[v a] (let x (head v)) (let xs (tail v)) - (let xa (prepend x a)) + (let xa (cons x a)) (match v [] a _ (_reverse xs xa)))) @@ -138,10 +138,10 @@ (match vs [] (match v delim [(reverse acc)] - otherwise [(prepend v (reverse acc))]) + otherwise [(cons v (reverse acc))]) otherwise (match v - delim (prepend (reverse acc) (_split-by delim [] vs)) - otherwise (_split-by delim (prepend v acc) vs))))) + delim (cons (reverse acc) (_split-by delim [] vs)) + otherwise (_split-by delim (cons v acc) vs))))) ; split vector by delimiter (let split-by (\[delim vals] |
