The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Block and Lambda

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Red Handed

Posts: 1158
Nickname: redhanded
Registered: Dec, 2004

Red Handed is a Ruby-focused group blog.
Block and Lambda Posted: Jul 27, 2005 2:59 PM
Reply to this message Reply

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
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded

Advertisement

This entry is a loose summary of Matz blog : 2005-06-30 , 2005-07-01 , 2005-07-21 , 2005-07-22 . And this entry is related to Ruby 2.0 block local variable and Function Call .

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

What do you think?

Read: Block and Lambda

Topic: VMWare and Smalltalk Previous Topic   Next Topic Topic: Ruby is Just Plain Evolution

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use