On Sep 12, 2010, at 1:37 PM, Tinco Andringa wrote:
> Lambda's feel a bit like second class citizens because of this. I
> think in Ruby it is important that syntax works as you would expect it
> to. Using :[] or :call is just not the first thing you'd expect to
> use. It kind of feels like lambda's are something that were added to
> ruby as an afterthought.

I think the cognitive dissonance you are describing with regard to
lambdas comes from thinking of them as functions rather than objects.

If you approach lambdas (and procs) as *objects* and not as functions
then the dissonance you describe goes away (at least it does for me).

It would be strange to argue that you should be able to treat an
expression (a plain local variable in the simple case) as a function
to be called:

  a = [1,2,3]
  s = "Hello World!"
  h = { :color => :red }

  a()    # These are calls to self.a, self.s, self.h
  s()    # and not implicit calls to some 'special'
  h()    # method associated with the objects referenced by
         # local variables a, s, and h

Why should a lambda instance

  l = lambda { |a,b| a + b }

behave any differently?

Ruby's current treatment of lambdas and procs seems very
self consistent to me while the various attempts to make
expressions that happen to evaluate to lambdas behave/look
like method calls feels like an ugly hack to me.

Gary Wright