diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-10-26 22:51:21 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-10-26 22:51:21 +0300 |
| commit | 89db88c88083aaabba412662d9da10102f519b8d (patch) | |
| tree | ac05da989c01aafca4c9a9167cc23754e0adff22 /core.fnl | |
| parent | eb5ac9685626493847340274a97a0e99c0231e7b (diff) | |
feature(core): add assoc function & test
Diffstat (limited to 'core.fnl')
| -rw-r--r-- | core.fnl | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -353,6 +353,21 @@ oppisite truth value." (fn inc [x] (+ x 1)) (fn dec [x] (- x 1)) + +(fn* assoc + "Associate key `k' with value `v' in associative `tbl'." + ([tbl k v] (doto tbl (tset k v))) + ([tbl k v & kvs] + (tset tbl k v) + (assert (zero? (% (length kvs) 2)) "expected even amount key-value args") + (var [i k v] [1 nil nil]) + (var (i k) (next kvs)) + (while i + (set (i v) (next kvs i)) + (tset tbl k v) + (set (i k) (next kvs i))) + tbl)) + {: apply : seq : first @@ -390,4 +405,4 @@ oppisite truth value." : reverse : inc : dec - } + : assoc} |