From: Trans Date: 2005-11-02T00:57:07+09:00 Subject: Re: Anonymous methods, blocks etc. (Cont. 'default block params') This is abit to the side, but maybe it would shed light on the discussion. I'm wondering why lambda's can't be like more methods. If I define a method: def meth ; 1 ; end and then type meth #=> 1 The output is immediate, 1. But with a lambda, i.e. an aynnomous method, this is not the case. lam = lambda do ; 1 ; end lam #=> # To get hold of a first class method we have to do method(:meth). Many of us have wanted something briefer (of course this ties into the whole UnboundMethod/Method/Lambda/Proc/Block craziness, nontheless...) So why not have the two on the same footing then? lam = lambda do ; 1 ; end lam #=> 1 And to get a reference to the actual lambda object maybe &lam and we can do it for methods: &meth #or &self.meth as the case may warrent I know that usually turns a lambda into a block, but in essense isn't that the same thing? Well if not then use another symbol. The important thing is now its clean and much more useful. We can actually drop in lambdas for local vars without perceptable difference. Very cool! Very useful! Okay, so how does this get back to the case at hand. Interestingly it would mean: def x ; 1 ; end and x = lambda do ; 1 ; end mean almost the same thing, except for two distinctions: 1) the lambda has closure, and 2) the lamda's x is a local var, while the def's x is on the instance level, like @x. And that's very interesing b/c that means def initialize @x = lambda do ; 1 ; end end @x is like having a local instance method! It also indicates that #def is like a method taking a special parameter 'x' --just like define-method: def( :x ) do ; 1 ; end So I think it's reasonable to deem that if that parameter is not given then it is annonymous so: x = def() do ; 1 ; end This is very much like what Dave suggested. And like him this def I imagine this should be *non-closure*. And we need another name for closure, that could be 'lambda', okay, but I'd prefer somthing shorter, like 'fn' or maybe with three letters like 'def' so maybe 'dfn' x = dfn do ; 1 ; end Of course these are special and should be keywords so then we can drop the 'do'. The only thing that sets them a part from other methods is that with 'def' a special parameter can appear in the front of the parameters to define an instance level name, i.e. the method name. I suppose the same can be done for dfn is we want to keep the closure. class X name = self.name dfn x ; name ; end end X.new.x #=> "X" I think that solves just about all the signifficant issues related to this. If Matz want's an '->' operator to basically mean 'dfn', that's his call, but I think maybe most people will be happier with a word form. Sorry to go on so long, but I HTH. T.