2014-07-08 16:55 GMT+02:00 John Gabriele <[email protected]>:
> 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))
(error-in-datastruct-p)
This gives:
user=> user=> ()
When I only remove the last @errors, I get:
user=> user=> (whiskey
bucket
nil chain
nil frog
nil pole
pole
nil ((No location for pole)))
What could be happening here?
The variables are defined with:
(def objects '(whiskey bucket chain frog pole))
(def ^:dynamic *object-locations* {
'whiskey 'living-room
'bucket 'living-room
'chain 'garden
'frog 'garden
'dummy 'nowhere
})
And I am using clojure 1.6.0.
By the way when changing *object-locations* to:
(def ^:dynamic *object-locations* {
'whiskey 'living-room
'bucket 'living-room
'chain 'garden
'frog 'garden
})
There is no problem, then I get the expected:
user=> user=> ((Number of objects and number of object locations is not the
same.))
--
Cecil Westerhof
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.