gwtmp01 / mac.com wrote:
> Right now there are some heuristics that allow the ruby parser to
> decide how to interpret an identifier with no associated arguments.
> In particular if it matches the name of a formal argument or it has
> appeared on the left hand side of an assignment, the parser assumes
> it is a variable.  Otherwise it assumes it is a 0-argument method call.
>
> Even with these rules we sometimes have to help the parser out by
> explicitly indicating that it is a method call:
>
>      self.attribute = value      # to avoid creating a local var
> 'attribute'

Right. And that's all it needs to do here. Nothing in this respect
changes.

> You are proposing that there be yet another interpretation that
> combines the behaviour of a variable with the semantics of a 0-argument
> method call:
>
>      magic_id
>
> gets interpreted as
>
>      magic_id.method
>
> but only if magic_id happens to be a reference to a particular kind
> of object (an "anonymous method").  Since there doesn't seem to be
> a syntactical way to spot an identifier with this magic behavior
> (indeed I believe you are asserting that the power of the proposal comes
> from the fact that there is *no* syntactical difference), then you
> are implying some sort of runtime check each and every time the
> identifier is evaluated.
>
> During this evaluation the "magic" occurs.  If the identifier actually
> references a special type of object then there is an implicit call
> to an predetermined method that results in a previously defined block/
> closure being executed.  The value yielded by this block "becomes" the value
> associated with the identifier.  In other words, 'magic_id' gets
> automatically interpreted as:
>
>      magic_id.call

I think you've made this appear more complicated than it is. It's not
so magical. A var references an object, so this amount to nothing more
than (psuedo)

  var.lamda? ? var.call ? var

under the hood. And I am sure there is very fast way to do this. Also,
there's actually no reason we can't have both forms, though I think
that might be less attractive for the language as a whole.

  lam = dfn ; 1 ; end
  lam1stclass = ->lam

> > If a method and a local var can be the same why not annoynous method
> > with local var name?
>
> I'm not sure I'm understanding your use of the term 'anonymous method'.
> I *think* it is something between a block/closure and a Proc object
> but it isn't either?  Can you explain how it differs from a standard
> Proc object or is the difference just in the alternative invocation?

The use of term is just what its called in the sense that it is not
tied to the method table, but to a free varaible. So this is possible:

  a = []
  a[1] = dfn ; 1 ; end

Ie. No fixed name. What they "are" is simply what Matz has designated
them as --they are methods except they do not have the fixed name and
they have closure. They differ from Proc only in subtle ways.

> > The trick is simply like that of dealing with
> > blocks --though I realize now some other symbolization will be needed
> > to differentiate block from passing first-class lambda object.
>
> So you are proposing some manner of reifying a block but you don't
> want to utilize a Proc object but some other new type of object?

I'm only proposing a different way of *referencing* what Matz is
already reifying.

> > I'm gogin to use Matz notation here for lack of anything else
> > (interestingly it actually makes some sense as "dereference")
>
> Matz notation is just a way of allowing Proc objects to have the
> same argument passing semantics/syntax as regular methods.  It still
> ends up creating a Proc object and still requires an explicit
> invocation of Proc#call to execute the associated block.

I realize. I was simply "borrowing" the notaiton. But I was delighted
at how well it worked.

> I wrote:
> >> It is pretty easy to package up define_method and have a very concise
> >> way to define methods on demand.
>
> You replied:
> > Sure, but this is very weak by comparision. Your using method_missing
> > for one, and as you say your defining methods into the singleton
> > space,
> > not anonymously.
>
> I just used method missing to make the *definition* simpler.  The
> resulting
> invocation syntax is the same regardless of how it is defined.
>
> I'm not sure how your method makes anything anonymous.  You are just
> proposing
> that a specific method be called under certain conditions in the way
> #to_proc
> is called on an argument prefixed with & or in the way #to_a is
> called when
> the 'splat' operated is used.  #to_proc and #to_a aren't anonymous
> they are
> just invoked indirectly according to the syntactical rules of the
> language.

Don't let the word "anonymous" get in the way --that just refers to the
fact it is a method kept independent of the method table. Nothing more.

Part of this idea has already been expiremented with in 1.9 with

  a = proc { 1 }
  a()  #=> 1

But this way doesn't do us as much good, and has serious issues b/c 'a'
is still the Proc object direct. Thus this "feature" was recently
removed. I'm offering an improved alternative, if you will.

T.