Re: A pipe macro for left-to-right coll streams

2009-02-14 Thread Perry Trolard
Hi Timothy, On Feb 12, 8:08 pm, Timothy Pratley wrote: > What should happen when/if the seq arg doesn't contain the symbol? I > believe how you currently handle it is correct and in the spirit of > let-> (alternatively it could be reported as an error) however it may > raise yet another possibi

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Timothy Pratley
That's very neat Perry! user=> (let-> [? 5] inc) 6 user=> (let-> [? 5] inc (+ 2 ?)) 8 user=> (let-> [? 5] inc (+ 2 ?) (+ ? 3)) 11 user=> (let-> [? 5] inc (+ 2 ?) (+ ? 3) (+ 4)) 4 What should happen when/if the seq arg doesn't contain the symbol? I believe how you currently handle it is correct a

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Perry Trolard
Sorry to keep revising things; here's an improved version of let->, which better supports (as near as I can tell -- please try to break) arbitrary let-style destructuring. (The previous version favored single-symbol bindings, but I can imagine use cases where [a b :as all] kinds of destructuring a

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread kyle smith
+1 as well for pipe and let-> --~--~-~--~~~---~--~~ 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+unsub

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread MattH
+1 for pipe and let-> as above, with the non-seq => (non-seq local) translation. --~--~-~--~~~---~--~~ 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 unsubs

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Perry Trolard
Let me amend: Instead of pipe-as, I think the symbol-binding version of the macro should be derived from the more common macro, which is -> & not pipe. So I'd vote for pipe & a let-> that takes a bindings vector as its first argument (sample implementation below). Perry (defmacro let-> "Like

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Perry Trolard
On Feb 12, 12:15 pm, Meikel Brandmeyer wrote: > > I dislike this strategy for two related reasons: (1) It cannont be > > nested. Here is a pseudo-example: > > > (?-> 2 ... some computations ... (f (?-> ... I don't have access to > > the outer "?" anymore... ))) > > > (2) Shadowing user bindings

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Meikel Brandmeyer
Hi, Am 12.02.2009 um 16:15 schrieb Mark Fredrickson: I dislike this strategy for two related reasons: (1) It cannont be nested. Here is a pseudo-example: (?-> 2 ... some computations ... (f (?-> ... I don't have access to the outer "?" anymore... ))) (2) Shadowing user bindings. If I bind ? t

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Mark Fredrickson
> There seems to be a general consensus that some sort of explicit form of threading would be useful. Below are snippets of other messages, outlining the remaining points. I should point out that we are not limited to one macro/function to handle our needs. For my own part, I think as wri

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Timothy Pratley
Dare I suggest it <- might be an interesting 'name' for 'pipe' given that -> calls in prefix and 'pipe' calls in postfix. But I'd rather not see it contending with Datalog which <- is nice to use. | isn't 'official', but it works fine... > and < aren't 'officially' usable in symbols either so wh

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread MattH
"Plus a macro makes for shorter syntax, which is part of its purpose." Yeah the shorter syntax becomes even more apparent when you're piping/ threading through one-arg functions where it also saves on parenthesis, as the "->" and "pipe" macros expand to a list if necessary. E.g. this code in a c

Re: A pipe macro for left-to-right coll streams

2009-02-12 Thread Konrad Hinsen
On 11.02.2009, at 18:18, Perry Trolard wrote: > In any case, I vote for approaching Konrad Hinsen about putting this > in clojure.contrib.macros when a naming convention is agreed on. When I started clojure.contrib.macros, I intended it as a repository for everybody's small macros that don't h

Re: A pipe macro for left-to-right coll streams

2009-02-11 Thread Perry Trolard
+1 for something like (let->). I don't imagine myself being confused by the reserved symbol being bound to different values in each successive form, or, in any case, would gladly trade that possibility for the advantage of being able to place the special symbol anywhere in the forms. Somewhat al

Re: A pipe macro for left-to-right coll streams

2009-02-10 Thread Mark Fredrickson
> > Maybe _ is appropriate? > > => (let-> _ (+ 1 2) (* 2 _) (+ _ 1)) > 7 > => (let-> _ [1 2 3] (map inc _) (reduce + _) (+ _ 3)) > 12 > > Or maybe ? ? Don't forget the wide variety of unicode symbols you have at your disposal: user=> (let-> ★ 2 (+ ★ 3) (- 10 ★ ) (map #(* ★ %) [2 3 4])) (10 1

Re: A pipe macro for left-to-right coll streams

2009-02-10 Thread Meikel Brandmeyer
Hi, Am 10.02.2009 um 23:34 schrieb Michael Reid: Maybe _ is appropriate? => (let-> _ (+ 1 2) (* 2 _) (+ _ 1)) 7 => (let-> _ [1 2 3] (map inc _) (reduce + _) (+ _ 3)) 12 Or maybe ? ? I would not use _. _ is often used as "don't care" variable name. And this is certainly not what we want here

Re: A pipe macro for left-to-right coll streams

2009-02-10 Thread Michael Reid
On Tue, Feb 10, 2009 at 5:02 PM, MattH wrote: > > The pipe macro is definitely not a new idea btw. It's taken from a > thread posted on another lisp group. > > Someone posted a silly inflammatory attack on lisp, contrasting unix: > "cat a b c | grep xyz | sort | uniq" > to how they'd imagine it

Re: A pipe macro for left-to-right coll streams

2009-02-10 Thread MattH
The pipe macro is definitely not a new idea btw. It's taken from a thread posted on another lisp group. Someone posted a silly inflammatory attack on lisp, contrasting unix: "cat a b c | grep xyz | sort | uniq" to how they'd imagine it in lisp: "(uniq (sort (grep xyz (cat a b c" A poster c

Re: A pipe macro for left-to-right coll streams

2009-02-10 Thread David Powell
I like the pipe macro. I get a bit cognitively overloaded when map/filter/reduce are nested, I think it is made worse because they have 2 or more arguments, so you have to do a lot of jumping around to follow them. The left-to-right style is much easier to follow. I'm not sure about let-> t

Re: A pipe macro for left-to-right coll streams

2009-02-09 Thread Jason Wolfe
> I like that implementation. The recursive call makes it much cleaner. > A slight improvement (?) yet: > > (defmacro let-> > "Provide a name that will be bound to the result of the first form. > For each additional form, the variable will be > used in the evaluation, and then rebound to the

Re: A pipe macro for left-to-right coll streams

2009-02-09 Thread Mark Fredrickson
I like that implementation. The recursive call makes it much cleaner. A slight improvement (?) yet: (defmacro let-> "Provide a name that will be bound to the result of the first form. For each additional form, the variable will be used in the evaluation, and then rebound to the result

Re: A pipe macro for left-to-right coll streams

2009-02-09 Thread Jason Wolfe
Nice, I would definitely use this! One comment/question: would it be more efficient to expand to a bunch of nested "let" statements, rather than nested function calls? I'm not sure how Clojure handles "let" under the hood, or how Hotspot inlining works here. Here's my version: (defmacro let->

Re: A pipe macro for left-to-right coll streams

2009-02-09 Thread Mark Fredrickson
This inspired me to write a general purpose version: (defmacro let-> "Provide a name that will be bound to the result of the first form. For each additional form, the variable will be used in the invocation, and then rebound to the result of the form." [varname start & forms] (let

A pipe macro for left-to-right coll streams

2009-02-08 Thread MattH
Hi, I want to suggest a "pipe" macro for dealing with collection streams, as a one-line variation on the built in "->" macro. Instead of writing a nested stream like this: ; "Take the first 3 elements of the odd numbers in the range 1 to 20" (take 3 (filter odd? (range 1 20))) you can write