« SoC, MacIntel, etc. | Main | HsSyck Cabalized. »

2006.04.30

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

foo .bar;  # foo($_.bar())

Ack. So where in P5 you say

foo()
    ->bar
    ->baz
    ->quux;

in P6 you’d have to say the following?

foo.
    bar.
    baz.
    quux;

(Notice the placement of dots vs arrows.)

I don’t like that any more than I like it when Ruby makes me do that… hopefully, `given` combined with the shortcut for invoking methods on the topic will mostly remove the need for method chaining.

Aristotle: Actually, you'd need to use the "long dot" form:

  foo\
      .bar\
      .baz\
      .quux

That is, "\" and "." separated by optional whitespace is an alternate spelling of the "." form. This hopefully provides sufficient visual clue on both sides as to not confuse people from either camp. :-)

I don’t know if I like where this is going… does this mean that

foo. bar;

is also wrong, and

foo\ .bar;

is necessary instead?

I have to say, sometimes I can really feel Abigail. :-(

Right, that is the case indeed. And yes, I agree with your feeling.

However, the Rubyish alternative of allowing "dangling" method calls:

$foo.
   bar(3).
   baz(4)

Really looks no cleaner to me...

I don’t like that either (and said so in the other comment). I wish it was possible to arrange the dots like the arrows in Perl 5:

foo
	.bar
	.baz
	.quux;

If that’s not possible I’m really hoping I can just rely on topicalisation instead…

given foo {
	.bar;
	.baz;
	.quux;
}

of course, those mean different things:

((foo.bar).baz).quux;

versus

foo.bar;
foo.baz;
foo.quux;

as a method call doesn't always return its invocant (nor would you always want it to).

They can mean different things. However, because Perl 5 does not have a syntactic shortcut for “$_->”, it is common practice to return the invocant from a method where there’s not something useful to return, so that you can chain method calls on the same invocant.

If such chains do mean something different in a lot of your code, that most likely just means the code is hard to read…

well, half (say) of the method calls i make are accessors, which want to return a piece or aspect or acquaintance of their invocant, and are especially useful in chains.

in any case, the idiom for stacked chaining now has to use whatever form long dot has (finally?) taken... if you can come up with a better form that will bear the design pressures on this new language, please speak up; i imagine there isn't anyone that's overjoyed with the latest syntax. it's meant to suggest '\' line continuations, so makes some sense to me, but still looks odd and rather ugly.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Comments are moderated, and will not appear until the author has approved them.

June 2014

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30          

Audrey

My Photo

License