This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
Original Post: Block and Lambda
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
Matz has been thinking about new syntax of block paremter and lambda expression.
As it stands, we can’t use same syntax in block parameter as in method parameter.
So he has some ideas, but he is not satisfied with these ideas.
We can write block parameters like this now:
hash.each { |k,v| v ||= "none"; ... }
Following examples mean the same.
1. Anonymous function like Perl6
This syntax came from Perl6:
for list -> x { ... }
Perl6 has a near cultural sphere to Ruby, so he think it’s well to refer Perl6.
But he worry whether Perl6 will be released or not and whether this syntax will be adopted in Perl6 or not.
hash.each -> (k,v="none") { ... }
This syntax is so-so in block because It reminds him of a substitution.
But when in lambda expression:
proc = -> (x, y) { ... }
Hmmm, it doesn’t look like a function.
2. Other sign
hash.each \(k,v="none") { ... }
In Haskell, back-slash sign means lambda because of form likeness.
A matter is a back-slash sign displays as yen-sign by font environment.
In lambda case:
proc = \(x, y) { ... }
In Ruby, it look like a parenthesis escaped.
3. Double back-slash
hash.each \\(k,v="none") { ... }
It’s lack of visual hint.
proc = \\(x, y) { ... }
He thinks better than one back-slash case.
He is worried by the same reason of font as one back-slash, too.
He thinks he should lays special emphasis on lambda expression,
because main dissatisfaction was an inconsistency that
a syntax of lambda’s parameters is different from syntax method’s parameter in the begining.
Though he will not choice below ideas probably, I introduce.
4. New keyword
hash.each { using k,v="none"; ... }
5. Extend lambda
hash.each(&lambda(k,v="none") { ... })
He leaned toward an example like Perl6 and had done at his local repository, but he wavers yet.
He wants a good idea which fulfill below condition:
It’s able to express anonymous function.
It puts in front of paraemters.
It’s good mix of sign which have not been used until now.