On Tuesday, July 8, 2014 11:38:42 AM UTC-4, Cecil Westerhof wrote: > > > > > 2014-07-08 16:55 GMT+02:00 John Gabriele <jmg...@gmail.com <javascript:>>: > >> On Tuesday, July 8, 2014 9:40:54 AM UTC-4, Cecil Westerhof wrote: >>> >>> In Clojure you can define a local constant with let, but I need a >>> variable (I think). >>> >>> I want to do the following. I have a function that checks several >>> things. Every time an error is found I want to set the variable errors to: >>> (concat errors new-error) >>> >>> Is this possible? Or is there a better way to do this? >>> >>> >> You *could* do something like: >> >> ~~~ >> (let [errors (atom []) >> ... >> (swap! errors conj "error-X") >> ...) >> ~~~ >> > > I al-ready tried something along those lines: > (defn error-in-datastruct-p [] > (let [errors (atom ())] > (if (= (count objects) (count *object-locations*)) > (map (fn [x] > (println x) > (if (not (*object-locations* x)) > (do > (println x) > (swap! errors conj (remove-symbol-from-output > `(No location for ~x))) > @errors > ) > )) > objects) > (swap! errors conj '(Number of objects and number of object > locations is not the same.))) > @errors)) > > `map` is for creating seqs (and lazy ones at that); it's not for side-effects. If you want side-effects, try `doseq`.
Also, just a matter of style, but it's customary to leave closing parens at the end of a line, rather than by themselves on their own line. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.