2014-07-09 4:19 GMT+02:00 Bob Hutchison <hutch-li...@recursive.ca>:

>
> On Jul 8, 2014, at 7:08 PM, Cecil Westerhof <cldwester...@gmail.com>
> wrote:
>
> 2014-07-08 23:11 GMT+02:00 Bob Hutchison <hutch-li...@recursive.ca>:
>
>>
>> On Jul 8, 2014, at 9:40 AM, Cecil Westerhof <cldwester...@gmail.com>
>> 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?
>>
>> Here's a different take on your question, and a few comments about how
>> I'd write that code. I don't think you need the atom -- kinda ugly and the
>> reduce/map/filter family of sequence functions will take you a long way.
>>
>> ; This is not a predicate, so don't use the -p suffix (and in Clojure
>> it's a ? normally)
>>
>
> ​As I understood it (I am rewriting land of lisp to Clojure) that when a
> function returns a true/false state, that you then use the -p suffix. When
> returning () there are no errors. But I should use the ? then?
>
>
> You’re returning a list of errors. You can interpret that as a
> truthy/falsy kind of thing, in which case make sure you’re returning a nil
> for the no-error case. And use the ‘?’ in Clojure.
>

​That I do with:
    (let [errors (atom ())]

I changed the name to 'error-in-datastruct?'.


By the way. The current function is only the start of the checks.​
>
> ​After the if I need to do several other checks also. So I think I do need
> the atom. But maybe I am mistaken. ;-)
>
>
> I thought maybe your checks would be a little more than that. That’s why I
> left the ‘reduce’ version in there. Just make the function that is applied
> by reduce more powerful, perhaps pull it out into a separate function
> rather than an inline anonymous function. This will work as long as all
> tests are performed on one object at a time.
>
> No matter what, I’d recommend not going using an atom if you can help it.
>

​I have my work cut out. But that is the best way to learn. :-D

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

Reply via email to