Pass by reference?

Thinking period over :wink:
In Ruby everything is passed by value, even Integers - or did I misread the
sources?
In that case my apologies Austin.
This is consistent with behavior as well as with implementation.
Is there any reason to tweak the meaning of "passing by reference" and
"passing by value" just because we use "reference" more often of how vars
designate (ty Wolfgang) values (which happen to be objects).
"Passing by designation", if it makes things clearer, why not, but we would
talk a language only Rubyists can understand!

Cheers
Robert

···

On 1/27/07, Robert Dober <robert.dober@gmail.com> wrote:

On 1/27/07, dblack@wobblini.net <dblack@wobblini.net> wrote:
>
> Hi--
>
> On Sun, 28 Jan 2007, Wolfgang Nádasi-Donner wrote:
>
> > dblack@wobblini.net schrieb:
> >
> >> Right -- I take that as the starting point -- but what I mean is that
> >> the way the assignment/rebinding semantics work doesn't necessarily
> >> pertain to the reference/value question.
> >
> > I agree. reference/value came from the world before talking about
> objects. I
> > remember in Algol60 somehow the wording "after 'integer i;' the
> variable 'i
> > IS an integer".
> >
> > We would never say that after writing "s = 'A Ruby String object'" the
> > variable 's' IS a String object - it gives a name for a special String
> > object, or references a special String object (see 1).
>
> There's also the distinction between references and immediate
> values... though as Robert K. said, most of the differences are
> hidden from the programmer (like, there's no extra level of
> indirection you have to explicitly do).
>
> > Wolfgang Nádasi-Donner
> >
> > (1): This wording is is used from a German, who tries to find out the
> best
> > English word for what in German will be called "benennt", or
> "bezeichnet". I
> > don't know what wording is really good in English.
>
> I think "betoken" is probably the closest etymologically to
> "bezeichnen", but it's more archaic-sounding. "Designate" might be a
> good match. (This is why we end up doing things like using
> "reference" as a verb :slight_smile:

Designated is just fine, I do not know the verb betoken.

However I do not necessarily agree with the post, still thinking...

Robert

--

"The best way to predict the future is to invent it."
- Alan Kay

--
"The best way to predict the future is to invent it."
- Alan Kay

Thinking period over :wink:
In Ruby everything is passed by value, even Integers - or did I misread the
sources?
In that case my apologies Austin.
This is consistent with behavior as well as with implementation.
Is there any reason to tweak the meaning of "passing by reference" and
"passing by value" just because we use "reference" more often of how vars
designate (ty Wolfgang) values (which happen to be objects).
"Passing by designation", if it makes things clearer, why not, but we would
talk a language only Rubyists can understand!

Cheers
Robert

···

On 1/27/07, Robert Dober <robert.dober@gmail.com> wrote:

On 1/27/07, dblack@wobblini.net <dblack@wobblini.net> wrote:
>
> Hi--
>
> On Sun, 28 Jan 2007, Wolfgang Nádasi-Donner wrote:
>
> > dblack@wobblini.net schrieb:
> >
> >> Right -- I take that as the starting point -- but what I mean is that
> >> the way the assignment/rebinding semantics work doesn't necessarily
> >> pertain to the reference/value question.
> >
> > I agree. reference/value came from the world before talking about
> objects. I
> > remember in Algol60 somehow the wording "after 'integer i;' the
> variable 'i
> > IS an integer".
> >
> > We would never say that after writing "s = 'A Ruby String object'" the
> > variable 's' IS a String object - it gives a name for a special String
> > object, or references a special String object (see 1).
>
> There's also the distinction between references and immediate
> values... though as Robert K. said, most of the differences are
> hidden from the programmer (like, there's no extra level of
> indirection you have to explicitly do).
>
> > Wolfgang Nádasi-Donner
> >
> > (1): This wording is is used from a German, who tries to find out the
> best
> > English word for what in German will be called "benennt", or
> "bezeichnet". I
> > don't know what wording is really good in English.
>
> I think "betoken" is probably the closest etymologically to
> "bezeichnen", but it's more archaic-sounding. "Designate" might be a
> good match. (This is why we end up doing things like using
> "reference" as a verb :slight_smile:

Designated is just fine, I do not know the verb betoken.

However I do not necessarily agree with the post, still thinking...

Robert

--

"The best way to predict the future is to invent it."
- Alan Kay

--
"The best way to predict the future is to invent it."
- Alan Kay

SORRY folks my gmail went amok!!!

The simplest way to remember this is that variables in Ruby aren't
chunks of memory. When C++ programmers say that they're passing
something by reference, they are simply doing a (slightly) safer
operation than passing a pointer around. They are *still* referencing
the memory block, but it's type checked.

In Ruby, inasmuch as variables contain anything, they contain a
reference. This applies even to immediate values such as nil, true,
false, integers, and symbols. It just so happens that, at least for
integers, the reference (the object ID, if you will) is the same as
the value, shifted left once -- at least in matzruby. The others are
all fixed object IDs.

Making a distinction between the passing semantics of immediate values
is a mistake; it invites people to peer too deeply under the hood of
Ruby. Better to clarify that integers are immediate immutable values
and indicate that all variables are references and the references are
passed -- by value -- to methods.

Scope also enters into this, but that's been discussed clearly.

-austin

···

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * http://www.halostatue.ca/feed/
               * austin@zieglers.ca

"Austin Ziegler" <halostatue@gmail.com> wrote/schrieb <9e7db9110701271150i30ae8023h27dfcae386a3629e@mail.gmail.com>:

The simplest way to remember this is that variables in Ruby aren't
chunks of memory.

Or: they are a chunk of memory, but the only kind of value they can
contain is a reference to an object. A variable is not such an object,
i.e. there are no references to variables.

Ruby

···

~~~~

Var. obj.-id object
      +---+ +---+
a --->| | | |
      > >--->| |
b --->| | | |
      +---+ | |
               > >
               > >
               > >
               > >
               +---+

If one passes a value, always an object id will be passed.

If one just uses variable ``a'', it will always go through the
automatial indirection of the object id. If ``a'' and ``b'' go through
the same indirection (using the same object id), then state can be
manipulated mutually.

C
~

Var. memory
      +---+
a --->| |
      > >
b --->| |
      > >
      > >
      > >
      > >
      > >
      +---+

If one passes a value, the memory will be copied. Then state can no
longer be manipulated.

Regards
  Thomas

It's better not to consider variables in Ruby as anything but a label
and as such *not* a chunk of memory. Chunks of memory suggest object
status or possibilities; this is not part of Ruby.

Your graphs are pretty close to correct. I have to finish some
articles talking about variables in Ruby and post them at some point.

-austin

···

On 1/28/07, Thomas Hafner <thomas@hafner.nl.eu.org> wrote:

"Austin Ziegler" <halostatue@gmail.com> wrote/schrieb <9e7db9110701271150i30ae8023h27dfcae386a3629e@mail.gmail.com>:
> The simplest way to remember this is that variables in Ruby aren't
> chunks of memory.
Or: they are a chunk of memory, but the only kind of value they can
contain is a reference to an object. A variable is not such an object,
i.e. there are no references to variables.

--
Austin Ziegler * halostatue@gmail.com * http://www.halostatue.ca/
               * austin@halostatue.ca * You are in a maze of twisty little passages, all alike. // halo • statue
               * austin@zieglers.ca