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")
  ...)
~~~

though, a more functional approach might look more like:

~~~
(loop [errors []
       things-to-check ...]
  (if (empty? things-to-check)
    errors
    (recur (conj errors (check (first things-to-check)))
           (rest things-to-check))))
~~~

-- John

-- 
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.

Reply via email to