2014-07-08 18:14 GMT+02:00 John Gabriele <jmg3...@gmail.com>: > 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>: >> >> 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`. >
That was the problem. I know have: (defn error-in-datastruct-p [] (let [errors (atom ())] (if (= (count objects) (count *object-locations*)) (doseq [obj objects] (if (not (*object-locations* obj)) (swap! errors conj (remove-symbol-from-output `(No location for ~obj))))) (swap! errors conj '(Number of objects and number of object locations is not the same.))) (reverse @errors))) And that works. > 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. > I do that also, but when I am editing I put them on there own line, because in this way changes are faster. When I am satisfied, I merge them. ;-) By the way I would like to put a point after the message, like: (swap! errors conj (remove-symbol-from-output `(No location for ~obj.))))) But that gives: CompilerException java.lang.ClassNotFoundException: obj., compiling:(NO_SOURCE_PATH:124:42) Is there a way to get the point behind the line? -- Cecil Westerhof -- 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.