But that would print 1 to 32 items depending on a ton of things. No the
correct way to write code like that is

(doseq [s coll]
  (println s))

If you need to iterate over multiple items then use (map f a b).

Also I would suggest benchmarking things, sure (map f coll) is slower than
a transducer, but benchmark your app code and I think you'll be surprised
how fast map is for normal use cases.

On Fri, Sep 23, 2016 at 4:04 PM, William la Forge <laforg...@gmail.com>
wrote:

> I've run into this when I wanted to print each item in a seq. Since
> println returns nil, I just did (first (keep println coll)). --Needed the
> first here because keep returns a lazy seq.
>
>
> On Friday, September 23, 2016 at 12:02:09 AM UTC-4, Mars0i wrote:
>>
>> This is almost the same as an issue I raised in this group over a year
>> and a half ago, here
>> <https://groups.google.com/forum/#!msg/clojure/bn5QmxQF7vI/vO1XLSyPXC8J;context-place=forum/clojure>.
>> I suggested that Clojure should include function with map's syntax but that
>> was executed only for side-effects, without constructing sequences.  No one
>> else was interested--no problem.   It's still bugging me.
>>
>> It's not map syntax that I care about at this point.  What's bugging me
>> is that there's no standard, built-in way to process multiple sequences for
>> side effects without (a) constructing unnecessary sequences or (b) rolling
>> my own function with loop/recur or something else.
>>
>> If I want to process multiple sequences for side-effects in the the way
>> that 'for' does, Clojure gives me 'doseq'.  Beautiful.  I can operate on
>> the cross product of the sequences, or filter them in various ways.
>>
>> If I want to process multiple sequences by applying an n-ary function to
>> the first element of each of n sequences, then to the second element of
>> each sequence, and so on, I can use 'map' or 'mapv', but that means
>> constructing unnecessary collections.
>>
>> Or I can splice my n sequences together, and make a single sequence of
>> n-tuples, and use doseq to process it.  (There's an example like this on
>> the doseq doc page.)  Or I can process such a sequence with 'reduce'.  More
>> unnecessary collections, though.
>>
>> Or I can use 'dotimes', and index into each of the collections, which is
>> OK if they're vectors, but ... ugh. why?
>>
>> Or I can construct my own function using first and rest or first and next
>> on each of my sequences, via loop/recur, for example.   But that seems odd
>> to me.
>>
>> Isn't this a common use case?  Is processing multiple sequences for
>> side-effects with corresponding elements in each application so unusual?
>> (Am I the only one?)  Isn't it odd that we have doseq and map but nothing
>> that processes multiple sequences for side-effects, in sequence, rather
>> than as a cross-product?
>>
>> (I admit that in my current use case, the sequences are small, so
>> creating a sequence of n-tuples would have only a trivial cost.  It just
>> bugs me, though. :-)
>>
>> I'd still be OK with something that had a map-like syntax, but my current
>> inclination is that it would be better for such a function to have
>> doseq-style syntax.  The name might be derived from "doseq"--maybe
>> "doseq*".
>>
>> (I'd be willing to suggest this in a JIRA ticket, but that doesn't seem
>> reasonable unless there's a call for something like this from more than one
>> person.)
>>
> --
> 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.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

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