On Wed, Oct 14, 2009 at 10:42 AM, Mark Tomko <mjt0...@gmail.com> wrote:
>
> Thanks, this was very helpful.


You're welcome.

Just to follow up on a few things - by SICP, do you mean the book
> "Structure and Interpretation of Computer Programs"?  That's the most
> likely match I could find.  I'm not familiar with the book, though, so
> I might have another reading project.
>

Yes, and it's available free online as a set of web pages. Someone else
already posted a URL.


> So, map et. al let me tandem-iterate multiple sequences?  I had an
> early implementation that did basically that using the 'for' list
> comprehension, but I couldn't figure out how to add an element to my
> result for some steps in the iteration and not others.


As others have noted, a) for actually iterates over the cross-product of the
collections instead of iterating them in tandem, and b) with for you can use
:with to selectively output.

A hack involving emitting and later filtering out a dummy object might have
occurred to you (and did occur to someone earlier in the thread, who used
:ignore). Such hacks can usually be avoided. If you ever do feel the need, a
keyword is tempting, as is nil, but to allow the full range of possible
results you need the dummy object to be guaranteed distinct from any
possible output. Fortunately there are two easy ways. One:

=> (let [d (Object.) e (Object.)] [(= d d) (= e e) (= d e)])
[true true false]

Any new vanilla java.lang.Object is distinct from any other, so you can (let
[dummy (Object.)] (remove #(= % dummy) (for ...))). If you're allergic to
having Java interop calls you could also use (let [dummy (gensym)] ...) and
again be assured that the data will never happen to contain a value equal to
dummy.

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

Reply via email to