About 1.9 #__method__ feature

Hi --

···

On Sat, 8 Jul 2006, ara.t.howard@noaa.gov wrote:

On Sat, 8 Jul 2006 transfire@gmail.com wrote:

object_id
object_class
object_send

Then for the all methods that bypass access resitrictions:

instance_send
instance_eval
instance_exec
instance_variable_get
instance_variable_set
instance_variables

That way it's consistant, intuitive, easy to use and easy to learn.

The only exceptions is #instance_of? But that's moot if you ask me b/c
it's safer to ask the class anyway. So preferably we would have
Class#class_of?(obj) plus a word alias for Module#=== like
Module#ancestor_of?(obj).

why not simply

send
send!

eval
eval!

exec
exec!

etc.

i like the idea - but those are long names! :wink:

Maybe Sean was right that you and I are really saying the same thing
in different ways :slight_smile: At least, we seem to have converged on "send!".

David

--
  "To fully realize the potential of Rails, it's crucial that you take
    the time to fully understand Ruby--and with "Ruby for Rails" David
       has provided just what you need to help you achieve that goal."
       -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
  Complete foreword & sample chapters at http://www.manning.com/black\!

Hi --

···

On Tue, 4 Jul 2006, Mauricio Fernandez wrote:

On Tue, Jul 04, 2006 at 12:39:12AM +0900, Yukihiro Matsumoto wrote:

Hi,

In message "Re: About 1.9 #__method__ feature." >> on Tue, 4 Jul 2006 00:31:03 +0900, dblack@wobblini.net writes:

>Speaking of send: is the 'funcall' name definite? Are you still
>interested in hearing arguments against it? :slight_smile:

Do you have a proposal for any alternatives? By the way, have you
noticed the alias "invoke_functional_method"?

hmmm the link between "might be called externally despite being private" and
"functional" is subtle, to say the least;
#invoke_private_method seems much clearer (even if inaccurate) and is nearly
as long if you want to discourage its use.

I think it's inaccurate to the point of really not being usable.

I admit I'm still a fan of send/send! but I guess they're long gone
:slight_smile:

David

--
  "To fully realize the potential of Rails, it's crucial that you take
    the time to fully understand Ruby--and with "Ruby for Rails" David
       has provided just what you need to help you achieve that goal."
       -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
   Complete foreword & sample chapters at http://www.manning.com/black\!

how bout

   invoke_method! # dangerous because invokes even private

??

-a

···

On Tue, 4 Jul 2006, Mauricio Fernandez wrote:

On Tue, Jul 04, 2006 at 12:39:12AM +0900, Yukihiro Matsumoto wrote:

Hi,

In message "Re: About 1.9 #__method__ feature." >> on Tue, 4 Jul 2006 00:31:03 +0900, dblack@wobblini.net writes:

>Speaking of send: is the 'funcall' name definite? Are you still
>interested in hearing arguments against it? :slight_smile:

Do you have a proposal for any alternatives? By the way, have you
noticed the alias "invoke_functional_method"?

hmmm the link between "might be called externally despite being private" and
"functional" is subtle, to say the least;
#invoke_private_method seems much clearer (even if inaccurate) and is nearly
as long if you want to discourage its use.

--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama

Hi --

In the old days, I used to herald the appearance of every 10K'th
message on this list. I don't do that any more... but I think message
#200000 is worth taking note of. Yes, yes, the count is probably off
due to this or that glitch over the years. But it's still cool,
especially because in spite of its growth and growing pains, this list
is still extraordinarily useful and collegial.

David "20K" Black

···

--
  "To fully realize the potential of Rails, it's crucial that you take
    the time to fully understand Ruby--and with "Ruby for Rails" David
       has provided just what you need to help you achieve that goal."
       -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
   Complete foreword & sample chapters at http://www.manning.com/black!

Well, a private method is not suppose to be invoked externally, so it's not really a "method call." That's my best guess at the reasoning...

James Edward Gray II

···

On Jul 3, 2006, at 10:59 AM, dblack@wobblini.net wrote:

I haven't noticed invoke_functional_method. I admit I'm still unclear
on the (new?) use of the notion of 'function' in addition to
'method'.... How do you characterize a functional method, in this
context?

Hi,

···

In message "Re: About 1.9 #__method__ feature." on Tue, 4 Jul 2006 00:59:21 +0900, dblack@wobblini.net writes:

I haven't noticed invoke_functional_method. I admit I'm still unclear
on the (new?) use of the notion of 'function' in addition to
'method'.... How do you characterize a functional method, in this
context?

I refer a method invocation without a receiver specified as
"functional style" because it looks like function calls in other
languages. The name "funcall" and "invoke_functional_method" reflect
that term.

              matz.

[...]
} maybe a meta-method to return all the info:
}
} #
} # an array of objects representing call record
} #
} where = __where__
}
} #
} # the first record is the call we're in
} #
} p where[0].file #=> same as __FILE__
} p where[0].method #=> same as __method__
} p where[0].line #=> same as __LINE__
} p where[0].binding #=> same as binding
}
} #
} # but this one reaches up like binding_of_caller
} #
} p where[1].file #=> same as __FILE__
} p where[1].method #=> same as __method__
} p where[1].line #=> same as __LINE__
} p where[1].binding #=> same as binding
}
} #
} # and even further!
} #
} p where[2].file #=> same as __FILE__
} p where[2].method #=> same as __method__
} p where[2].line #=> same as __LINE__
} p where[2].binding #=> same as binding
}
}
} basically i'm proposing a 'caller' like interface which returns an array
} of objects having all the 'location' information, including
} scope/binding. this could be amazingly useful.

+1

I like that!

} regards.
} -a
--Greg

···

On Tue, Jul 04, 2006 at 12:48:18AM +0900, ara.t.howard@noaa.gov wrote:

I think this is a sign of how broken caller() is. Ara's version seems much more Rubyish to me.

James Edward Gray II

···

On Jul 3, 2006, at 10:48 AM, ara.t.howard@noaa.gov wrote:

basically i'm proposing a 'caller' like interface which returns an array of
objects having all the 'location' information, including scope/binding. this
could be amazingly useful.

Hi,

···

In message "Re: About 1.9 #__method__ feature." on Tue, 4 Jul 2006 00:48:18 +0900, ara.t.howard@noaa.gov writes:

# an array of objects representing call record
#
  where = __where__

I think there must be better name than __where__ for this
functionality. I think __where__ would give us more simple value like
mere string or a number, by association with __FILE__ etc.

              matz.

Hi,

No problem. I will try to paint better picture. I have variant of
OpenStruct called OpenObject:

class OpenObject < BasicObject #(this is my BasicObject like
BlankSlate)
   ...

Using BasicObject as parent removes (almost) all kernel methods which
ensures no name clashes when using the OpenObject. Problem is sometimes
those removed methods are needed. So the important ones are available
by shadow methods, like __send__ even though #send is removed. Problem
is A) how many and which kernel methods should be shadowed; all of
them? and worse B) it means users have to be aware when a subclass of
BasicObject might be used and call the LCD, ie. shadow methods instead
of regular methods.

I don't know what you expect for BasicObject and OpenObject.
BasicObject is a BasicObject what it is. Could you describe what you
want and what you expect first please? BasicObject may not be the
answer for your problem. If it's not the right answer, tweaking it to
adopt your requirement might not be a good idea.

I came up with one idea that fixes A. using #__self__, eg.

o = OpenObject.new
o.class #=> nil
o.__self__.class #=> OpenObject

What does this __self__ do?

What were the sticking points?

Separating it would break Ruby's object model. It would make it much
more complex at least, far more complex than I can bear.

I spent some time considering this and
arrived at a conception of layers, almost like subclassing, eg
MyClass:Public < MyClass:Private.

? Sorry, I don't get it.

              matz.

···

In message "Re: About 1.9 #__method__ feature." on Tue, 4 Jul 2006 02:07:30 +0900, transfire@gmail.com writes:

indeed - 'instance_send' gives me carpal tunnel just thinking about it! :wink:

-a

···

On Sat, 8 Jul 2006 dblack@wobblini.net wrote:

Maybe Sean was right that you and I are really saying the same thing
in different ways :slight_smile: At least, we seem to have converged on "send!".

--
suffering increases your inner strength. also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama

dblack@wobblini.net wrote:

Maybe Sean was right that you and I are really saying the same thing
in different ways :slight_smile: At least, we seem to have converged on "send!".

But Matz want's to get away from #send, and for good reason -- it's too
likely to be overriden, which is the whole reason we ended up with
__send__. So by it's very nature it needs to be more unique and there
are only two ways to achieve that: make it longer or make it esoteric.
I prefer longer.

T.

Hi --

···

On Tue, 4 Jul 2006, ara.t.howard@noaa.gov wrote:

On Tue, 4 Jul 2006, Mauricio Fernandez wrote:

On Tue, Jul 04, 2006 at 12:39:12AM +0900, Yukihiro Matsumoto wrote:

Hi,

In message "Re: About 1.9 #__method__ feature." >>> on Tue, 4 Jul 2006 00:31:03 +0900, dblack@wobblini.net writes:

>Speaking of send: is the 'funcall' name definite? Are you still
>interested in hearing arguments against it? :slight_smile:

Do you have a proposal for any alternatives? By the way, have you
noticed the alias "invoke_functional_method"?

hmmm the link between "might be called externally despite being private" and
"functional" is subtle, to say the least;
#invoke_private_method seems much clearer (even if inaccurate) and is nearly
as long if you want to discourage its use.

how bout

invoke_method! # dangerous because invokes even private

I suggested send! long ago, but Matz didn't like it.

David

--
  "To fully realize the potential of Rails, it's crucial that you take
    the time to fully understand Ruby--and with "Ruby for Rails" David
       has provided just what you need to help you achieve that goal."
       -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
   Complete foreword & sample chapters at http://www.manning.com/black\!

Yeah, I'm with David in that I liked send/send!, so this seems a natural extension to me.

James Edward Gray II

···

On Jul 3, 2006, at 11:03 AM, ara.t.howard@noaa.gov wrote:

On Tue, 4 Jul 2006, Mauricio Fernandez wrote:

On Tue, Jul 04, 2006 at 12:39:12AM +0900, Yukihiro Matsumoto wrote:

Hi,

In message "Re: About 1.9 #__method__ feature." >>> on Tue, 4 Jul 2006 00:31:03 +0900, dblack@wobblini.net writes:

>Speaking of send: is the 'funcall' name definite? Are you still
>interested in hearing arguments against it? :slight_smile:

Do you have a proposal for any alternatives? By the way, have you
noticed the alias "invoke_functional_method"?

hmmm the link between "might be called externally despite being private" and
"functional" is subtle, to say the least;
#invoke_private_method seems much clearer (even if inaccurate) and is nearly
as long if you want to discourage its use.

how bout

  invoke_method! # dangerous because invokes even private

??

>hmmm the link between "might be called externally despite being private"
>and "functional" is subtle, to say the least; #invoke_private_method seems
>much clearer (even if inaccurate) and is nearly as long if you want to
>discourage its use.

I think it's inaccurate to the point of really not being usable.

Conceded. #invoke_even_if_private also came to mind but it seems a bit
excessive.

I admit I'm still a fan of send/send! but I guess they're long gone
:slight_smile:

I also like it (! never really meant "danger" to me).

···

On Tue, Jul 04, 2006 at 01:00:30AM +0900, dblack@wobblini.net wrote:

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby

Hi --

I haven't noticed invoke_functional_method. I admit I'm still unclear
on the (new?) use of the notion of 'function' in addition to
'method'.... How do you characterize a functional method, in this
context?

Well, a private method is not suppose to be invoked externally, so it's not really a "method call." That's my best guess at the reasoning...

I can see that point, but I'm not sure how it leads to the concept of
a functional method. It seems like all of these permutations could be
built on the basic message-sending paradigm, where the act of the
caller (sending a message) is separate from the act of the object
(deciding what to do in response to the message).

To me, "funcall" and anything referring directly to method-invocation
do a short-circuiting of that paradigm.

By contrast, consider:

   obj.method(:m).call

In this case, the caller has to go through a separate step -- which I
think is good. I wouldn't want to see that turned into:

   obj.method_call(:m)

David

···

On Tue, 4 Jul 2006, James Edward Gray II wrote:

On Jul 3, 2006, at 10:59 AM, dblack@wobblini.net wrote:

--
  "To fully realize the potential of Rails, it's crucial that you take
    the time to fully understand Ruby--and with "Ruby for Rails" David
       has provided just what you need to help you achieve that goal."
       -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS.
  Complete foreword & sample chapters at http://www.manning.com/black\!

How about __context__ ?

···

On 7/3/06, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:

Hi,

In message "Re: About 1.9 #__method__ feature." > on Tue, 4 Jul 2006 00:48:18 +0900, ara.t.howard@noaa.gov writes:

># an array of objects representing call record
>#
> where = __where__

I think there must be better name than __where__ for this
functionality. I think __where__ would give us more simple value like
mere string or a number, by association with __FILE__ etc.

Yukihiro Matsumoto wrote:

Hi,

>No problem. I will try to paint better picture. I have variant of
>OpenStruct called OpenObject:
>
> class OpenObject < BasicObject #(this is my BasicObject like
>BlankSlate)
> ...
>
>Using BasicObject as parent removes (almost) all kernel methods which
>ensures no name clashes when using the OpenObject. Problem is sometimes
>those removed methods are needed. So the important ones are available
>by shadow methods, like __send__ even though #send is removed. Problem
>is A) how many and which kernel methods should be shadowed; all of
>them? and worse B) it means users have to be aware when a subclass of
>BasicObject might be used and call the LCD, ie. shadow methods instead
>of regular methods.

I don't know what you expect for BasicObject and OpenObject.
BasicObject is a BasicObject what it is. Could you describe what you
want and what you expect first please? BasicObject may not be the
answer for your problem. If it's not the right answer, tweaking it to
adopt your requirement might not be a good idea.

OpenObject is just like OpenStruct, but it is faster and removes
methods that would get in thte way using BasicObject, for example
#class. More detailed example:

  require 'facet/openobject'
  require 'ostruct'
  oo = OpenObject.new
  os = OpenStruct.new
  oo.class = "foo" #=> "foo"
  os.class = "foo" #=> "foo"
  oo.class #=> "foo"
  os.class #=> "OpenStruct"

Also BasicObject can be useful for any class that uses method_missing
since it removes kernel methods that would not otherwise be missing.

What does this __self__ do?

class BasicObject

  # The Self class allows one to get access the hidden Object/Kernel
methods.
  # It is essentially a specialized Functor which binds an
Object/Kernel
  # method to the current object for the current call.

  class Self < self
    def initialize(obj, as=nil)
      @obj = obj
      @as = as || ::Object
    end
    def method_missing(meth, *args, &blk)
      @as.instance_method(meth).bind(@obj).call(*args, &blk)
    end
  end

  # Returns the Self functor class, which can then be used to
  # call Kernel/Object methods on the current object.

  def __self__
    @__self__ ||= Self.new( self )
  end

  # This method is like #__self__, but allows any ancestor
  # to act on behalf of self, not just Object.

  def __as__( ancestor )
    Self.new( self, ancestor )
  end

>What were the sticking points?

Separating it would break Ruby's object model. It would make it much
more complex at least, far more complex than I can bear.

>I spent some time considering this and
>arrived at a conception of layers, almost like subclassing, eg
>MyClass:Public < MyClass:Private.

? Sorry, I don't get it.

Acutally I have that backward, sorry. MyClass:Private <
MyClass:Public.The idea beng that the public layer is like a superclass
to the private layer. Outside access is directed to the Public layer
and internal access directed to the Private layer. So clearly if a
method isn't in the private layer it goes back to the public layer.
Private layer could even call super to access public layer. So it's
like dividing a class inot two transparently cojoined classes.

T.

···

In message "Re: About 1.9 #__method__ feature." > on Tue, 4 Jul 2006 02:07:30 +0900, transfire@gmail.com writes:

Yukihiro Matsumoto wrote:

I refer a method invocation without a receiver specified as
"functional style" because it looks like function calls in other
languages. The name "funcall" and "invoke_functional_method" reflect
that term.

What about "invoke_function"? It's not accurate but mixing, "function" and "method" in the same name seems to be mixing two concepts that are mutually exclusive. Like saying "blackish white".

BTW I also like the send/send! syntax (not that it seems to matter at this point)

Daniel

Gregory Seidman wrote:

···

On Tue, Jul 04, 2006 at 12:48:18AM +0900, ara.t.howard@noaa.gov wrote:
} basically i'm proposing a 'caller' like interface which returns an array
} of objects having all the 'location' information, including
} scope/binding. this could be amazingly useful.

+1

+2, it's brilliant! "where" is a bit non-descriptive though; "callstack" or something similar to "caller" might be better. I've somtimes wanted a way to get at the binding of the caller but Binding.of_caller is just too much of a hack and I can't bring myself to use it. But this would be a very elegant solution.

Daniel