On Nov 18, 11:18 am, Robert Ewald <[EMAIL PROTECTED]> wrote:
> On Tuesday 18 November 2008 08:20:15 mb wrote:
>
>
>
> > Hi,
>
> > On 18 Nov., 03:01, Adam Jones <[EMAIL PROTECTED]> wrote:
> > > I'm in the middle of writing some code to extract sql results, which
> > > means I'm doing a *lot* of forcing right now. It's almost enough for
> > > me to wish there was a convention (and provided definitions) for
> > > denoting lazy/strict versions of functions. (e.g. (map f ...) is a
> > > lazy seq, (map! f ...) is strict)
>
> > For what it's worth: I use the following convention.
>
> > - For code which is purely done for side-effects, I use doseq. eg.
> > (doseq [x some-seq] (println x))
>
> > - In case I want to have the seq in memory, or there are side-effects
> > and I need the actual results, I use doall.
> > (doall (map some-f some-seq))
>
> > On the other hand: you can simply create your own map!.
> > (def map! (comp doall map))
>
> > Just my 0.02€.
>
> > Sincerely
> > Meikel
>
> Right, but this is precisely the reason for my asking. I was aware you could
> create a macro, but if I do that a lot nobody could read my code any longer.
> Everyone creating his own set of misguided utilities has been an argument
> against lisp, and I think this is a function of communication inside the
> community.
>
> Using a ! to signify forcing is interesting, even though I am reserved because
> scheme is using it to signify side effects and clojure is not free from side
> effects.
I used it as a shorthand for a similar bit of syntax in Haskell. There
$! is defined such that f $! x forces the evaluation of x before
handing it to f. map$! would be ugly, but I see your point about !.
(in fact, Clojure already uses this for set! on threadlocal vars)
Maybe map$ would be a good choice; it even sort of conveys the idea
that needlessly forcing a computation can be (spatially) expensive! =)
Ultimately the choice of a character to signify "this function is not
lazy" isn't a big issue, so long as it is 1. not confusing and 2.
vaguely memorable. Maybe Rich can step in with an opinion and settle
this.
-Adam
>
> Anyway, I suppose that doseq is the right idiom for communicating that you
> want throw away the results.
>
> --
> Robert Ewald
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---