Re: a = Dog.new # a is not a pointer and not a reference?




On Sep 29, 2007, at 10:17 PM, SpringFlowers AutumnMoon wrote:

Morton Goldberg wrote:
On Sep 29, 2007, at 8:18 PM, SpringFlowers AutumnMoon wrote:

Come to think about it, a pointer is very clear cut... an alias is
very
clear cut. but when it is "reference", then you have to think whether
it is the pointer behavior or the alias behavior.

No, you do not. Ruby has it own semantics, which do not correspond
with the semantics of C or C++. Trying to impose the semantics of
other languages onto Ruby isn't going to work. It's best to drop such
baggage and start fresh.

hm,... but is there a problem to think of reference in Ruby as a
"pointer"? will that cause any trouble? I only see that a.value is
not the same as C and C++ would use a->value, but in Ruby we use the "."
to replace the "->" and that's it. Will there be further trouble or
discrepancy to think of Ruby reference as a pointer?

Well, your assertion that a.value is the equivalent of a->value is a good example of getting into trouble by equating a reference to a pointer. The expression a.value is a method call, not a value fetch. For a.value to work, the object referred by a has have a method called 'value', either an instance method or singleton method, in its extended object table. If it does, the method is executed and some object is returned. That's not at all what a->value does in C.

Regards, Morton

.



Relevant Pages

  • Re: Question on LSP
    ... Sure, the developer must keep track of which type has been assigned to each pointer to manage complexity in creating the design, which is why the 'T' is in T*. ... Subtyping is a relation which does not ... Those object types are completely orthogonal to the semantics of being an object reference. ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Question on LSP
    ... Because construction paradigms have different goals. ... But that has nothing to do with what a pointer type ... But that does not mean that the semantics of an object reference is ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Question on LSP
    ... equivalent addresses in the same context. ... Note that the language allows us to use a name like 'T' on the reference as a mnemonic so that the developer can keep track of what is happening with the indirection. ... Modern languages have proper pointer types. ...
    (comp.object)
  • Re: Nothing Keyword Destories Objects rather than just resetting the variable to an empty variable
    ... there is no difference between using ByVal or ByRef. ... as the C1 pointer was the sole reference to the class object. ... Yes, an object variable is a pointer to an object, but that is the only ... the keyword "NOTHING" should only destroy the ...
    (microsoft.public.excel.programming)
  • Re: How java passes object references?
    ... to think of them as being a specific location in a larger block of memory ... Whether a language passes by reference or by value, ... is a pointer pointing at the memory block. ... So when allocating local memory for o, it would simply allocate a ...
    (comp.lang.java.programmer)