Matz offered a number of options for lambda (anonymous function)
creation syntax during his keynote. Figure I can comment as some of
the thoughts are subtle. My gut reaction was to stick with
lambda
but something itched. I think I figured it out,
but let's look at options.
f = lambda (x=5)
puts x
end
f = lambda (x=5) { puts x }
f = -> (x=5) { puts x }
f = (x=5) { puts x }
f = def (x=5)
puts x
end
The thing that bugged me about *all* of these is that the default
value for the parameter (x=5)
looks like it is
being evaluated, not like a default value. This highlights, for
instance, a big difference between python and ruby, in python the
(x=5)
is a statement, not an expression, and isn't the
default in that context. I dislike this about python.
Oddly enough, the syntax I like the least, f = -> (x=5) { puts
x }
is probably the clearest for this as, visually, the arrow
looks like it pushes the parens into the function def, kind
of. Really, I want the params to be inside the block, I think, like
the current goal posts. One thing suggested by the audience was the
groovy method, f = { x=5 -> puts 5 }
, which I quite
like, and Matz thought about, but dismissed as looking too much like
a hash ( { :x => 5 }
, which it does, I agree =(
Blocks and anonymous functions will remain different, and I
certainly trust Matz on this, though I don't see the reasoning
personally =) If they are, then... maybe something block like is
good. Matz seems pretty set on having parens for the args outside of
the block, and I cannot say I disagree -- I just don't want the
confusion over whether (x=5)
is an assignment in the
scope of the definition, or a default value in the scope of the
invocation (execution in aspectj terms).
Aside from that, fantastic presentations by Ryan Davis and Jim Weirich on cool ruby hacks in the afternoon, nice (and really interesting) case studies in the morning. I had the advantage of sitting next to one of the Io hackers (Brian Mitchell) most of the day, so picked his brain some, and played with Io. Interesting. Also installed Forth based on breakfast conversation. Have to muck with a language described as "kind of low level -- higher than assembly, lower than C" =) Slate still wins the "my brain hurts the most" award, so I doubt I'll stop focusing the majority my language muckery on it for the most part for a while =)