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

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



On Wed, 20 Jun 2001, Israel 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.

If you're coming from a C background, it might(!) help to think of Dylan's
variables as "implicit pointers".  Actually these "variables" are called
"bindings", where a "binding" makes a "name" point to a "value".

They're not quite like pointers, because you don't "dereference" them (and
so you can't ever get an access violation (unless you interface to C or
something ;-)).  They're not quite like C++ references either because, if
you pass one to a function, you can see changes to the content of the
object but not changes to "what the variable points to".  That is, if my
C++ isn't too rusty ...

--------
void someFunction () {
  Foo& myFoo = new Foo(RED);
  frob(myFoo);
  // [1]
}

void frob (Foo& foo) {
  // At point [1], both C++ and Dylan could see changes to the innards
  // of an object, like this:
  foo.colour = BLUE;
  // At point [1], C++ will see the following, because it changes myFoo,
  // but Dylan won't because we're only changing the local binding "foo":
  foo = new Foo(GREEN);
}
--------

Does that unconfuse you at all?  I think the "implicit pointers" analogy
is easiest if you come from C.

Hope that helps,
Hugh

-- 
Version 3.1 GCS/IT d- s+:+>+: a- C++$ UL P+ L+(++) E W++$ N++ o K++ w(++) O?
M V? PS(+) PE Y+ PGP->++ t(+) 5+(++) X(+) R tv b++ DI+ D+ G e++ h- r>++ y+
(Removed reversed spam from my email address to reply)




Follow-Ups: References: