> Date: Mon, 9 Dec 2002 06:00:40 +0100 > From: =?iso-8859-1?Q?St=E9phane?= Payrard <[EMAIL PROTECTED]>
> Damian: > > so it's easy to build up more complex right-to-left pipelines, like: > > > > (@foo, @bar) := > > part [/foo/, /bar/], > > sort { $^b <=> $^a } > > grep { $_ > 0 } > > @data; > > > > > > I would like perl6 to support left-to-right part/sort/grep pipelines. > Left to right syntax is generally good because it facilitates the flow > of reading. > > For these pipelines, the current right to left syntax is due to the emphasis > on the operation over the data operated on, so the operator appears > first. Nevertheless with a long pipeline, data is best factored out in a > variable so having it first is not an impediment. [snip] I was just playing with Mathematica and thinking this very same thing. Mathematica has an operator // that applies arguments on the left to the function on the right. I was just thinking how good that was for clarity. To do some awful computation, and get a numeric result, you can write: N[awful computation] Or: awful computation // N I was instantly reminded of TMTOWTDI, in a good way. Perhaps Perl could adopt a similar mechanism? The operator in question should have very low precedence. >> is available, I think, since bitops are prefixed with . or whatever. $0{statement}{expression}{additive_expression}[0] >> print; That's rather nicer, IMHO, than: print($0{statement}{expression}{attitive_expression}[0]); You could even give a closure: $0{...} >> { print $^v, "\n" } Not that anyone would. The situation is analogous to that of: die "Can't do it" unless something; versus something or die "Can't do it"; It allows for moving the important stuff out to the left (Depending on what you consider important). @a >> grep { $_ > 0 } >> sort >> { print $^v, "\n"} Aha! That's when you use the closure. Unix pipelines are so nice to script with, why shouldn't Perl steal them? :) > Also, I am not necessarily advocating that operators like := > could be flipped to become := with flipped operands: > > @data...grep { $_ > 0 }...sort { $^b <=> $^a }...part [/foo/, /bar/] =: (@foo, >@bar) > > I am just advocating to examine the idea. :) > I certainly see an imediate problem with the current conventions: > =~ and ~= are two different beasts, not one beast and its flipped version. Yeah... I don't think that would work so well. There's just too many operators that have meanings both ways. Luke