Comments on: Day 9: Having beautiful arguments (and parameters)https://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/
Something cool about Perl 6 every daySat, 11 Jul 2015 12:32:35 +0000hourly1http://wordpress.com/By: carlhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-521
Tue, 14 Dec 2010 15:21:49 +0000http://perl6advent.wordpress.com/?p=179#comment-521Oops, that was a thinko on my part — the &action does need to be specified. Now corrected in the post. Thanks.

A few random comments: a Perl 6 compiler with the appropriate presence of mind would flag such an omission at compile time. (There’s no such compiler yet, but it’s definitely possible.) Regardless, the code wouldn’t make it through runtime since the signature binding would fail.

I was once sitting at a dinner table opposite Damian Conway and Larry Wall. Larry was pondering adding a special code-parameter, as in Ruby, with a special syntactic exception so that omission of a comma for a block specified inline would not be an error, as it is now in Perl 6. That idea was just idle speculation, though, and hasn’t made it into spec.

]]>By: szeryfhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-520
Tue, 14 Dec 2010 15:13:41 +0000http://perl6advent.wordpress.com/?p=179#comment-520Why isn’t the action parameter used in recursive calls to traverse_inorder? Is the code-parameter special (as in Ruby)? Or (if it’s normal) can we use more than one code-parameter (unlike in Ruby)?
]]>By: carlhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-214
Thu, 24 Dec 2009 09:30:58 +0000http://perl6advent.wordpress.com/?p=179#comment-214I think the point where I really fell in love with the short form of named parameters was when I realized that they can be used even with variables that have a twigil (secondary sigil) — for the purposes of the parameter naming, it’s simply ignored. So these examples all work:

sub outer { inner(:$^some-arg); } # :some-arg($^some-arg)

configure-io(:$*IN); # :IN($*IN)

method build() { precompute-stuff(:$!a, :$!b, :$!c); } # :a($!a) etc.

]]>By: Daniel Brockmanhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-213
Thu, 24 Dec 2009 02:01:01 +0000http://perl6advent.wordpress.com/?p=179#comment-213A similar short form for named parameters exists in O’Caml:

To pass 123 as the value of the named parameter “foo”, you use this syntax:

~foo: 123

But if you have 123 stored in a variable called “foo”, you can simply do this:

~foo

It’s very, very convenient, and it also all but forces you to name your variables and parameters thoughtfully and consistently. Good move to include this feature in Perl 6.

I’m looking forward to having chained operations so much nicer in Perl 6.

]]>By: carlhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-78
Wed, 09 Dec 2009 14:40:16 +0000http://perl6advent.wordpress.com/?p=179#comment-78The short form of named arguments is really, really nice. Not least because it interacts seamlessly with twigils (by ignoring them) — something that only becomes a desired feature after a while, when you suddnely think “hm, will it work if I do this? It cannot possibly work if I do this…” …and it does!

I’m really impressed with the short form of named parameters. I think no other language could possibly do this right now. (Well, maybe you could do it in Common Lisp with macros.)

]]>By: Moritzhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-76
Wed, 09 Dec 2009 09:25:11 +0000http://perl6advent.wordpress.com/?p=179#comment-76There’s a branch in Rakudo where lots of things are reworked (the ‘ng’ branch, if anybody is curious). On that this piece of code faithfully reports Cannot assign to readonly value.

We expect that branch to land some time this month, or at the very latest due to the release in January.

]]>By: Moritzhttps://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-75
Wed, 09 Dec 2009 09:22:05 +0000http://perl6advent.wordpress.com/?p=179#comment-75Instead of split and grep you can also use "73..." =~ /(.{7})/g, to stay closer to the Perl 6 version :-)
]]>By: ?https://perl6advent.wordpress.com/2009/12/09/day-9-having-beautiful-arguments-and-parameters/#comment-74
Wed, 09 Dec 2009 08:44:27 +0000http://perl6advent.wordpress.com/?p=179#comment-74If you’re a Perl 5 user, and feel left out looking at the last one-liner, here’s something roughly equivalent: