From: ES Date: 2005-10-17T08:32:33+09:00 Subject: Re: Anonymous methods, blocks etc. (Cont. 'default block params') Wilson Bilkovich wrote: > I agree. It seems to me that once Ruby has 'real deal' anonymous > methods, then that's a primitive that could be used to implement the > other constructs, like Proc. The hurdle for this, I assume (apart from having to rewrite a lot of code and another important thing addressed below), is that the closure feature does not play nice with the current semantics: # Pseudosyntax to clarify class Foo @quux = 42 def :foo {|x, y, z| do_something_with x, y, z } def :do_something {...} end The closure would grab the environment; @quux would be available and the implicit 'self' would refer to the Class object, not the instance. This means that all messages to a given object would invoke some sort of an #instance_eval on the method's code. (Please correct me and voice other *technical* issues if any!) These are by no means unsurmountable but there is quite a bit of work involved in rewriting. One big thing, though: one may wish to intentionally make a distinction between a 'behaviour' of an object and a 'function' which these anons (and to an extent Procs) can be seen as. I have made my peace by just thinking of this as a different way of defining those behaviours (it is not like they actually spawn to life by themselves now) but I can, sort of, see how the thought might seem unappealing. > Also, I've been trying not to comment on the arrow thing, but my > biggest complaint is this: > In functional notation, an 'f arrow x' means apply the f function to > the x argument. The example Ruby syntax is reversing that, and using > the arrow for specifying a function, rather than using it. > > --Wilson. > > On 10/16/05, robertj wrote: > >>hi, >> >>are there any non obvious issue why blocks, anonymous methods and >>methods could or should not be unified? >> >>i find it very ugly that i have to call a proc like this >>aproc.call or aproc[] instead of aproc(). unification of all those >>constructs would be really great. >> >>btw will be possible to get a handle on a instance method in ruby >>1.9/2.0 >> >>something like this: >>aproc = &anInstance.method >> >>and then of course >>aproc() >> >>ciao robertj E