lambda 式 (2)

も加えてみる。


Matz is thinking about new syntax of block paremter and lambda expression.
As it stands, we can't use same syntax as method parameter in block parameter.
So he has someideas, 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.

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.(★一文で whether 2度使うと変じゃない?)

hash.each -> (k,v="none") { ... }

This syntax is so-so in block because It reminds me of a substitution.


But when in lambda expression:

proc = -> (x, y) { ... }

Hmmm, it doesn't look like a function.(★関数っぽくない)


Other sign

hash.each \(k,v="none") { ... }

In Haskell, back-slash sign means lambda because of form likeness.
A matter is that back-slash sign displays as yen-sign by font.

In lambda case:

proc = \(x, y) { ... }

In Ruby, it look like a parenthesis escaped.


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.(★長ぇ〜)
(See Function Call)


Though he will not choice below ideas probably, I introduce.

New keyword

hash.each { using k,v="none"; ... }

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.
  • Many people feel comfortable (if possible).

What do you think?



理由は書かずにコード例でヤイヤイ話題にしてもらった方が良いような気がしてきた今日この頃。