[Prev][Next][Index][Thread]

Re: Newbie surveying the multitudes of Programming Langs...



On Wed, 20 Jun 2001 17:49:01 GMT, Israel <Israel@lith.com> wrote:
>>
>> whoops!   actually that was a mixup!   That weird thing was a feature
>> of the Oz language ( a concurrant something or other language)..
>> Instead of assignin a value to a variable it binds a variable to a
>> value.  Say if you have a car class, and it has an odemeter property.
>> Make a car called car1 and have it's odometer = 10000.  Make Car2 =
>> car1.  change Car2's odemeter to equal 0 and you'll find that car1's
>> odometer is now 0 as well.  It just strikes my newbie brain as goofy.
>
> Whoops again..  That's not a mix up!  it actually is Dylan that does
> this.  Sorry.  I just expect "magical" copying to occur due to my
> limited experience with C like stuff.

The easiest way to think about variables in Dylan is to think of them
as labels you paste onto objects.

Imagine that you have an instance of <car>, maybe a VW Beetle. When
you do

  let car-1 = make(<car>);

what happens is that first, you create a <car>, and then you use the
let operation to paste a little sticky note labeled "car-1" onto
it.

Let's suppose that car.odometer == 0, since this is a new <car>.

So if you then do:

  let car-2 = car-1;

what this means is "find the object with the sticky-note 'car-1', and
paste another note labelled 'car-2' to it." You haven't copied
anything -- you now have a <car> with two sticky labels on it. So if
you then

  drive-ten-thousand-miles(car-1);

Naturally the odometer(car-1) and odometer(car-2) will have the same
reading, 10000, since they both refer to the same <car>, and it just
drove ten thousand miles. 


Neel



References: