diff --git a/examples/utils.dst b/examples/utils.dst new file mode 100644 index 00000000..8f252e33 --- /dev/null +++ b/examples/utils.dst @@ -0,0 +1,22 @@ + +(defn put-in [coll keys val] + (defn assoc [the-coll n] + (if-let [current-key (get keys n) + current-val (get the-coll current-key)] + (put the-coll current-key (assoc current-val (inc n))) + val)) + (assoc coll 0)) + + +(defn update-in [coll keys an-fn] + (def new-keys (array-slice coll 0 -2) ) + (def last-key (get (array-slice coll -1 -2) 0)) + (defn assoc [the-coll n] + (if-let [current-key (get keys n) + current-val (get the-coll current-key)] + (put the-coll current-key (assoc current-val (inc n))) + ( update the-coll last-key an-fn ))) + (assoc coll new-keys 0)) + + +;; (defn update-in-test [ ] (update-in @{:a "x" :b {:y {"pipa" 3}}} [:b :y "pipa"] type)) diff --git a/src/compiler/boot.dst b/src/compiler/boot.dst index ab6ed174..1ee72f11 100644 --- a/src/compiler/boot.dst +++ b/src/compiler/boot.dst @@ -371,7 +371,6 @@ If no match is found, returns nil" all the forms with let and evaluates the first expression else evaluates the second" [bindings then else] - #(tuple 'print (tuple '> (tuple 'length bindings) 2)) (tuple 'let bindings (tuple 'if (tuple 'and (tuple 'get bindings 1) (tuple 'if @@ -384,8 +383,7 @@ If no match is found, returns nil" "Takes the first one or two forms in vector and if true binds all the forms with let and evaluates the body" [bindings & body] - (def head (ast-unwrap1 bindings)) - (tuple 'let head + (tuple 'let bindings (tuple 'when (tuple 'and (tuple 'get bindings 1)