Hi,
=20
In message "Re: Anonymous methods, blocks etc. (Cont. 'default block pa= rams')"
=20
|Is the -> syntax still open for debate Matz? I agree with Austin on=20
|this. The syntax here is just ugly.
=20
It's always open. But define "ugly" first.
=20
matz.
Here are some of my thoughts on the syntax "->(a=3D5,b=3D1){ }" to denote=
it as ugly.
* -> is not a common construct in any language that I know of to repres=
ent anonymous function=20
declaration, while lambda is. Instead -> is a recognized operator for der=
eferencing
* -> can be hard for readability given code like:
m=3D->(a,b){a**b}
OR
m=3D->(a,b){ arr =3D [];a.times { |i| arr << i**b } }
in my opinion it is easier to visually separate such constructs utili=
zing identifiable word=20
construct like lambda:
m=3Dlambda(a,b){ a**b }
OR
m=3Dlambda(a,b) {
arr =3D []
a.times { |i| arr << i**b }
}
* utilizing other operators such as assignment or comparison (although =
I don't know where someone=20
would use comparison operators here) cause visual confusion, and makes it=
easier for programmer to=20
overlook the correct interpretation of the code:
m=3D->(a,b){ .. } sort of looks like m=3D>a(b){ ...block here..=
}
whereas
m=3Dlambda(a,b){ ... } is hard to confuse with any other operator=
s
* Aesthetically, in my opinion -> as an operator is not as elegant as o=
ther ruby constructs such=20
as things like:
lambda { }
proc { }
do ... end
:symbol
The one area where there is another such constructor is with regular =
expressions, /.../, but=20
that seems to be universally used construct for regular expressions.
Now if you do not agree with my opinions and you choose to keep -> would =
it be possible to have:
->(a,b){ .. }
and
lambda(a,b){ }
have the same behavior?
On another note of the questions raised by your blog and translated by _w=
hy the following questions=20
are statement is set forth:
"He wants a good idea which fulfill below condition:
* It=92s able to express anonymous function.
* It puts in front of parameters.
* It=92s good mix of sign which have not been used until now.
* Many people feel comfortable (if possible)."
Would the following example fulfill the first two capabilities and potent=
ially the fourth?
proc =3D lambda (a, b=3D5){ a**b }
If you do not want to change behavior of lambda, I have another question.=
proc_lambda just calls=20
proc_alloc. It looks like proc_lambda is either being used as a placehold=
er for a better=20
implementation (anonymous function?) or it was just an easy way to implem=
ent lambda and make people=20
happy a few years ago.?
Also, according to your examples of using "->" with blocks. Example:
for list -> x { ... }
hash.each -> (k,v=3D"none") { ... }
I do not think the "->" can be used in:
proc =3D -> (x, y) { ... }
and keep the same consistency and clarity. Also would the following repla=
ce existing block syntax?
hash.each -> (k,v=3D"none") { ... }
Or would the above code and the existing block syntax both remain?
In your blog Matz you mention that you are considering -> operator becaus=
e of Perl6. Ruby has a=20
strong user base now and it is growing. People like many of the similarit=
ies that Ruby has with=20
Perl, but many of those same people are very happy that you did not pull =
over things from Perl like=20
hash or array dereferencing. I think the -> operator is one of these spo=
ts where it should be left=20
in Perl. Let perl people use ugly symbol based operators so it can add co=
nfusion, let ruby people=20
use something better. Also I do not claim to know what the better is. Per=
haps it is lambda, perhaps=20
it is something else....
Thank you for your time Matz to review this.
Zach
As references I reviewed the following sources:
-
http://redhanded.hobix.com/inspect/blockAndLambda.html
-
http://www.rubyist.net/~matz/?date=3D20050722 (babelfish translation, s=
imilar to redhanded blog above)
-
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/161133 (the=
whole thread)
-