First, I have to say thanks.  I'm only a part-time Clojure user, and I
didn't know of the -> macro until today.  Second, I think the ->
syntax leads to more readable code for precisely those situations
where you're coding a sequence of actions.  Finally, I've got a
comment about what I think might be a useful addition to Clojure.

In my day job, I've been using F#.  F# has a |> operator which relies
on automatic currying to do what, at first blush, I though the ->
macro did.  In other words, if you've got, for example,  a list of
data in F#, you can do something like:

    listOfNum |> (map someFn) |>  (filter anotherFn) |> max   ;; note
the brackets aren't necessary
                                                                                
        ;;
I  added them for readability

which is functionally equivalent to:

    max ( filter anotherFn (map someFn listOfNum)))

I quickly learned the -> macro can't be used in the same way for one
simple reason; the value that is threaded through to the forms is
always placed in the first argument position.  How about adding a
macro -- it could be called |> just as in F# -- that places the value
in the last argument position?  (It's dead simple to write -- I just
copied and modified the -> macro.)

With the new macro it would be possible to write code like:

    ( |> list-of-num
        ( map some-fn )
        ( filter another-fn )
        ( max ))

instead of:

    (max (filter another-fn (map some-fn list-of-num)))

IMHO, the |> macro, just like the -> macro, makes the sequence of the
actions much easier to follow.

Cheers,
--
BF




On Feb 27, 1:39 pm, "John D. Hume" <duelin.mark...@gmail.com> wrote:
> On Wed, Feb 25, 2009 at 4:11 PM, Jason Wolfe <jawo...@berkeley.edu> wrote:
> > (you'll get use to reading inside-out quickly).
>
> As a Java/Ruby guy who is not used to reading inside out, I'm curious
> as to whether people who ARE accustomed to LISP find the -> macro
> distracting since it flops things around. Are there circumstances
> where you prefer it?
--~--~---------~--~----~------------~-------~--~----~
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 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to