Clojure: how to avoid eval-ing the not-found expression in map get -
I have a map called "code> robots looking at the map, if given a robot by the given key If not present then I want to make one. However, it seems that I agree completely, but if your map has incorrect or zero values, its implementation will not work. Here's a more accurate solution: and fancy macro: To eliminate the possibility of generating some side-effects again < Code> Walk , eg: not found RG is exactly the same as I want.
is not found expression is evaluated eagerly. How can I stop this assessment so that I can create a new robot, if someone is not present?
robot> (Def robot {1 {: name "R2D2"}}) # 'robot / robot robot & gt; (Get robot1) {: name "R2D2"} robot & gt; (Get robot 1 (printlane "fight it")) This (i.e. "R2D2"}
(If robot 1 is included) (get robot 1) (printline "beep boop"))
(defmacro get-small [map key not found] `(map # ~ map key # key) (Includes # map # key included) (get the map # key # ~))
(lazy {1 false}} (printline "side effect") 1) (printlane "oh!")) < / Code>
Comments
Post a Comment