TkText no -textvariable workaround?

Dossy dossy@panoptic.com writes:

Speaking academically, the receiver is object a, the method is =(x).
[…]
But seriously, I think Dossy is mistaken… except in the
special case of attribute writers and accessors, assignment
is never considered to be a method call in Ruby. Correct?

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

Yes, you’re absolutely right in that sense.

I wonder how Ruby would have been different if Object#=(x) were defined
as an alias to #replace

Actually, I’ve wondered the same thing. Sometimes I think this would
be good. Sometimes it seems bad. Usually I just don’t know. :slight_smile:

In a “radically object-oriented” language like Ruby, it seems natural
that assignment would be a method (as it is even in C++ and Java).

This leads me to think there must be a good reason why it is not
implemented this way.

Matz? :slight_smile:

Cheers,
Hal Fulton

···

----- Original Message -----
From: “Dossy” dossy@panoptic.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 12:40 PM
Subject: Re: TkText no -textvariable workaround?

On 2002.07.17, Hal E. Fulton hal9000@hypermetrics.com wrote:

Dossy dossy@panoptic.com writes:

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

So, say we have

a = “hello”
a = 1

Then ‘a’ autovivifies as some proto-object that supports ‘=(x)’. When
executed, it in turn executes #becomes(x) so that ‘a’ is now a
String. When the second assignment is executed, then the String object
executes ‘=(x)’, issues another #becomes(x), and ‘a’ is now a Fixnum.

Then we have

a = 2

Now we have something interesting. The Fixnum ‘1’ that is currently
‘a’ now becomes the Fixnum ‘2’. But Fixnums are immediate values, so
how are we to implement this? Do all '1’s become ‘2’?

It’s the same problem with any singleton object:

a = true
a = false

How can true become false?

A variable is not an object: it’s a reference to one. There is no
object ‘a’.

Now there may be an object, accessible via reflection, that describes
variable ‘a’, but that’s different.

Cheers

Dave

Hi –

Dossy dossy@panoptic.com writes:

Speaking academically, the receiver is object a, the method is =(x).
[…]
But seriously, I think Dossy is mistaken… except in the
special case of attribute writers and accessors, assignment
is never considered to be a method call in Ruby. Correct?

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

I wonder how Ruby would have been different if Object#=(x) were defined
as an alias to #replace

Well, first there would have to be an Object#= :slight_smile: Also I think what
you’re describing is more like (the non-existent but sometimes
proposed) #become than #replace, at least the way the various
#replace’s work in Ruby.

I’m not clear on what’s at stake here, though, in practical terms.
(Even we academics have our practical moments :slight_smile:

David

···

On Wed, 17 Jul 2002, Dossy wrote:

On 2002.07.17, Hal E. Fulton hal9000@hypermetrics.com wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Hi –

From: “ts” decoux@moulon.inra.fr
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Cc: ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 12:23 PM
Subject: Re: TkText no -textvariable workaround?

If self has an attribute named ‘a’, then the receiver is self, and
the
method is ‘a=’.

No, `a’ is always interpreted as a local variable in this example

Very perceptive. True even if
you do this:

class Object
attr_accessor :a
end

Within the object, I guess you
always need self to access something
like this. Any exceptions to this?

I think that the only case you have to use self is when you’re doing
assignment (to prevent it from being taken for a local variable). If
you’re calling a reader method, you can do just ‘a’:

irb(main):001:0> class Thing; attr_accessor :a; def thing; puts a;
end; end
nil
irb(main):002:0> t = Thing.new; t.a = 3; t.thing
3

Yes, but I’ll bet if you had a local variable ‘a’
inside ‘thing’ you’d have to disambiguate with ‘self’…

Hal

···

----- Original Message -----
From: “David Alan Black” dblack@candle.superlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 4:23 PM
Subject: Re: TkText no -textvariable workaround?

On Wed, 17 Jul 2002, Hal E. Fulton wrote:

----- Original Message -----

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

I wonder how Ruby would have been different if Object#=(x) were defined
as an alias to #replace

I only know of one OO language, Self, where assignments are actually
implemented as message sends. In Self, there are only objects and messages.
Even stack frames are objects that you send messages to.

Slots (local variables and instance variables) are never visible to the
programmer. Declaring a slot on an object actually declares two methods on
that object, a getter and a setter, that get and set the slot value using
some implementation-dependent mechanism. A local variable is implemented as
getter/setter methods on the local stack frame.

To translate into Ruby terms, the statement “a = x” is conceptually sending
the message “a= (x)” to the local stack frame, rather than sending the
message “=(x)” to a.

Cheers,
Nat.

···

From: “Dossy” dossy@panoptic.com


Dr. Nathaniel Pryce
B13media Ltd.
Studio 3a, Aberdeen Business Centre, 22/24 Highbury Grove, London, N5 2EA
http://www.b13media.com

Wed, 17 Jul 2002 02:47:08 +0900, Hal E. Fulton hal9000@hypermetrics.com pisze:

In a “radically object-oriented” language like Ruby, it seems natural
that assignment would be a method (as it is even in C++ and Java).

It would not make sense in a language like Ruby (and almost all
other languages, including Java) where variables reference objects,
not contain objects.

Only C++, C, Pascal, Perl and some older languages are different.
Because they copy objects passed around the program unless explicit
pointers/references are used to indirectly refer to them. In C++
here:

std::string x;
std::string y;
x = "some string";
y = x;

x and y are different objects (they can at most share their payload
by a complex machinery under the hood), and ‘y = whatever’ doesn’t
create a new object for y but changes contents of an existing object.

It’s hard to share objects in C++ because of explicit memory
management. You would have to know when other parts of the program
are no longer interested in an object. It’s easier to make a copy
and destroy each separately.

C++ encourages imperative programming. Sharing is troublesome and
copying is expensive, so you often modify objects in place.

That approach worked well where most objects are simple things like
numbers. It gets much worse with tree-like structures which like
to have shared parts.

In Ruby objects are naturally passed by reference, explicit pointers
with an additional indirection are not needed. When you store an
object in a data structure or in a variable, only a reference to an
existing object is written, there is no copy created.

It’s common that two variables refer to the same object. If ‘=’ was a
message sent to that object which replaced its contents with contents
of another object, the change would be visible through both variables!

Well, it would be worse: you couldn’t express that sharing at all.
If assignment made a copy, how would you refer to an existing object
to see changes done inside it? Would passing objects as arguments
perform the same copying? Now it’s the same as using ‘=’ to bind them
to parameters!

You don’t modify the object inside the variable. You modify the
variable to let it point to another object. It’s a fundamental
difference. It allows to have one mechanism of passing objects around
and holding them with variables.

Since sharing is common, modifications of objects in place are more
dangerous. You might forget that another part of the program refers
to that object while it was meant to have a snapshot of its state
from an earlier time. You either use methods which treat objects as
immutable and return new objects with changed contents (those without
‘!’ at the end), or remember to .dup objects as needed.

These are two basic models of passing objects around. They shouldn’t
be confused, you can’t take parts of one system into another. The
difference is quite fundamental and easily forgotten, because in
overall it causes similar effect in case of assignments of atomic
objects like numbers (immutable in Ruby, mutable in C++).

···


__("< Marcin Kowalczyk
__/ qrczak@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/

Dossy dossy@panoptic.com writes:

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

So, say we have

a = “hello”
a = 1

Then ‘a’ autovivifies as some proto-object that supports ‘=(x)’. When
executed, it in turn executes #becomes(x) so that ‘a’ is now a
String. When the second assignment is executed, then the String object
executes ‘=(x)’, issues another #becomes(x), and ‘a’ is now a Fixnum.

Then we have

a = 2

Now we have something interesting. The Fixnum ‘1’ that is currently
‘a’ now becomes the Fixnum ‘2’. But Fixnums are immediate values, so
how are we to implement this? Do all '1’s become ‘2’?

Perhaps the problem is that Fixnum’s are immediate values. Why
is this?

In a pure OO implementation, Fixnum’s shouldn’t exist. There
should just be Numbers which inherit from Object, and perhaps
Integer, Float, and so on, that inherit from Number.

It’s the same problem with any singleton object:

a = true
a = false

How can true become false?

a.replace(TrueClass.dup) ?

A variable is not an object: it’s a reference to one. There is no
object ‘a’.

Why must variables exist? Why can’t there be a Object#reference that
returns a reference to an object, so that:

a = b.reference

Makes a an ObjectReference that delegates to b.

Realize: I’m not speaking about what Ruby current does but what
I might want or expect it TO do.

– Dossy

···

On 2002.07.17, Dave Thomas Dave@PragmaticProgrammer.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

Dossy dossy@panoptic.com writes:

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

[much snippage]

Very interesting and enlightening. This is probably
the real reason, I guess, that Ruby works this way.

Now we have something interesting. The Fixnum ‘1’ that is currently
‘a’ now becomes the Fixnum ‘2’. But Fixnums are immediate values, so
how are we to implement this? Do all '1’s become ‘2’?

OT: This stirs a dim memory in my mind. Sorry I keep reminiscing and regressing to the past -- it's a quirk of advanced age (I recently turned 41).

In older versions of FORTRAN, there was a simple way of
doing just that – I forget how it worked – a COMMON
block or something? You could have a stored “constant” 1
and change it (say) to 2… upon which every 1 referenced
as a constant in the program would be changed to a 2
internally (since the compiler pooled its constants). So
a statement MYVAR = 1 would then assign the value 2 when
it was executed… amazing language, FORTRAN. Usually when
you’re given enough rope to hang yourself, you gain
flexibility and power as a benefit. Not in this case!

Hal Fulton

···

----- Original Message -----
From: “Dave Thomas” Dave@PragmaticProgrammer.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 1:01 PM
Subject: Re: TkText no -textvariable workaround?

In a “radically object-oriented” language like Ruby, it seems natural
that assignment would be a method (as it is even in C++ and Java).

C++ only defines assignment when you are assign to an object.
Assignments to pointers and references are not methods. Object
assignment is very limited. The resulting object is “sliced” to fit
into the allocation memory location. You can assign objects of child
classes into an object of a parent class, but the resulting object
will be a Parent object (not a child). Polymorphism go right out the
door.

Unless my brain is failing me, I don’t recall assignments as methods in Java.

> This leads me to think there must be a good reason why it is *not*
> implemented this way.

I think that thinking of “a = b” as an assignment is the wrong way of
looking at it. Languages like FORTRAN, Pascal, and even C/C++ tend to
think of variables as shoeboxes into which you place a value. The
shoebox is a holder for the value.

Languages like Lisp have a different view. In Lisp, names are bound
to the values they represent. The name doesn’t reference a memory
location (i.e. shoebox) that can hold a value. The name is bound to a
value because there is a namespace (sometimes called an alist or
association list) that mentions the name and value together.

I have found it benificial to think of Ruby assignments to be more
like Lisp style name binding, rather than an C++ like assignment
statements. But I’m not sure I can articulate the reasons I find this
view better. Does this strike a chord with anyone else?

···


– Jim Weirich jweirich@one.net http://w3.one.net/~jweirich

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)

From: “Dossy” dossy@panoptic.com

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

I wonder how Ruby would have been different if Object#=(x) were defined
as an alias to #replace

I only know of one OO language, Self, where assignments are actually
implemented as message sends. In Self, there are only objects and messages.
Even stack frames are objects that you send messages to.

Right. (IIRC, I believe Smalltalk also implements assignments as
message sends and everything is an object or a message as well.)

To translate into Ruby terms, the statement “a = x” is conceptually sending
the message “a= (x)” to the local stack frame, rather than sending the
message “=(x)” to a.

Right. Thanks for correcting me!

– Dossy

···

On 2002.07.17, Nat Pryce nat.pryce@b13media.com wrote:


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

It would not make sense in a language like Ruby (and almost all
other languages, including Java) where variables reference objects,
not contain objects.

no, i think you take this too far. it makes a lot of sense in a language
like ruby, but does require a seperation between assignment and
reassignment, if you will. in other words x = “a” would not necessarily
be the same as x = String.new(“a”), [of course a new literal could be
used] in the later case you are creating an object, x, and making it a
string. in the former you are reassigning the object, x.

Only C++, C, Pascal, Perl and some older languages are different.
Because they copy objects passed around the program unless explicit
pointers/references are used to indirectly refer to them. In C++
here:

std::string x;
std::string y;
x = "some string";
y = x;

x and y are different objects (they can at most share their payload
by a complex machinery under the hood), and ‘y = whatever’ doesn’t
create a new object for y but changes contents of an existing object.

It’s hard to share objects in C++ because of explicit memory
management. You would have to know when other parts of the program
are no longer interested in an object. It’s easier to make a copy
and destroy each separately.

C++ encourages imperative programming. Sharing is troublesome and
copying is expensive, so you often modify objects in place.

That approach worked well where most objects are simple things like
numbers. It gets much worse with tree-like structures which like
to have shared parts.

In Ruby objects are naturally passed by reference, explicit pointers
with an additional indirection are not needed. When you store an
object in a data structure or in a variable, only a reference to an
existing object is written, there is no copy created.

unfortuanltly a couple of ruby objects are not passed by reference,
notably FIXNUM. personally, i have already run into a couple instances
where this “knocked me off my horse”, and i think it a bad idea to mix
things up like this. perhaps there is good reason, but if it is one of
speed, i’d rather buy a faster processor and more memory that have this
inconsistancy.

It’s common that two variables refer to the same object. If ‘=’ was a
message sent to that object which replaced its contents with contents
of another object, the change would be visible through both variables!

yes, but not replacement of contents.

Well, it would be worse: you couldn’t express that sharing at all.
If assignment made a copy, how would you refer to an existing object
to see changes done inside it? Would passing objects as arguments
perform the same copying? Now it’s the same as using ‘=’ to bind them
to parameters!

no, no copying.

You don’t modify the object inside the variable. You modify the
variable to let it point to another object. It’s a fundamental
difference. It allows to have one mechanism of passing objects around
and holding them with variables.

Since sharing is common, modifications of objects in place are more
dangerous. You might forget that another part of the program refers
to that object while it was meant to have a snapshot of its state
from an earlier time. You either use methods which treat objects as
immutable and return new objects with changed contents (those without
‘!’ at the end), or remember to .dup objects as needed.

(aside, would it be possible for ! methods to be an automatic creation?
just seems like there might be a way to define a method such that the !
version of it is automatically is deduced from it and that this could be
used through out ruby. just a thought.)

These are two basic models of passing objects around. They shouldn’t
be confused, you can’t take parts of one system into another. The
difference is quite fundamental and easily forgotten, because in
overall it causes similar effect in case of assignments of atomic
objects like numbers (immutable in Ruby, mutable in C++).

i think there are some deeper consideration to this. if ruby were to
take one more step in the direction of OO, becoming a Radical OOP, i
think it would discover another level (or at least semi-level) of power.

since everything is a subclass of object, there’s no reason that objects
can’t switch identities above that. we would be able to call-back on
such reassignments and create all sorts of neat “automagical” stuff.
also one could conrol class access at a much finer level.

it would not force us to use pass by assignment instead of pass by
reference. in fact the opposite is true.

~transami

···

On Sat, 2002-08-03 at 05:59, Marcin ‘Qrczak’ Kowalczyk wrote:


__("< Marcin Kowalczyk
__/ qrczak@knm.org.pl
^^ Blog człowieka poczciwego.


~transami

Sat, 3 Aug 2002 22:04:18 +0900, Tom Sawyer transami@transami.net pisze:

no, i think you take this too far. it makes a lot of sense in a
language like ruby, but does require a seperation between assignment
and reassignment, if you will. in other words x = “a” would not
necessarily be the same as x = String.new(“a”),

Well, in this sense it’s already done: your reassignment is spelled
x.replace(y). But not all objects are mutable (and that’s good)
and this variant is not used by default.

How would you store a reference to an object? Explicit pointers with
dereferencing?

unfortuanltly a couple of ruby objects are not passed by reference,
notably FIXNUM.

It doesn’t matter. It behaves as if passed by reference, except a few
weird cases not relevant to our problem (like singleton methods).
If an object is immutable and we don’t compare object identities, the
effect of passing it by reference and copying its value is the same.

(aside, would it be possible for ! methods to be an automatic creation?
just seems like there might be a way to define a method such that the !
version of it is automatically is deduced from it and that this could be
used through out ruby. just a thought.)

Only if all relevant objects have a universal ‘.replace’.

i think there are some deeper consideration to this. if ruby were to
take one more step in the direction of OO, becoming a Radical OOP, i
think it would discover another level (or at least semi-level) of power.

Sorry, I’m not a fan of OOP (though I am a fan of ruby). And I don’t
think that making ‘=’ copy values would be more radically OO.

since everything is a subclass of object, there’s no reason that
objects can’t switch identities above that.

There is: now we can freely pass immutable objects by reference and
not worry that somebody changes their contents.

Copying is a more fragile concept than rebinding references. When the
mutable state of an object is held in subobjects, it’s not clear how
deep we want the copy to be. Rebinding references is clear.

···


__("< Marcin Kowalczyk
__/ qrczak@knm.org.pl
^^ Blog człowieka poczciwego.

Hal E. Fulton wrote:

···

----- Original Message -----
From: “Dave Thomas” Dave@PragmaticProgrammer.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 1:01 PM
Subject: Re: TkText no -textvariable workaround?

Dossy dossy@panoptic.com writes:

I did say “academically” – in a pure OO language where everything
is an object, the receiver would be the object a, and the method – or,
the message being sent, would have been “=(x)” …

[much snippage]

Very interesting and enlightening. This is probably
the real reason, I guess, that Ruby works this way.

Now we have something interesting. The Fixnum ‘1’ that is currently
‘a’ now becomes the Fixnum ‘2’. But Fixnums are immediate values, so
how are we to implement this? Do all '1’s become ‘2’?

OT: This stirs a dim memory in my mind. Sorry I keep reminiscing and regressing to the past -- it's a quirk of advanced age (I recently turned 41).

In older versions of FORTRAN, there was a simple way of
doing just that – I forget how it worked – a COMMON
block or something? You could have a stored “constant” 1
and change it (say) to 2… upon which every 1 referenced
as a constant in the program would be changed to a 2
internally (since the compiler pooled its constants). So
a statement MYVAR = 1 would then assign the value 2 when
it was executed… amazing language, FORTRAN. Usually when
you’re given enough rope to hang yourself, you gain
flexibility and power as a benefit. Not in this case!

Hal Fulton

Was that run76, or was it FTN? Or did more than one Fortran compiler
have that bug?


– Charles Hixson
Gnu software that is free,
The best is yet to be.

Hi –

A variable is not an object: it’s a reference to one. There is no
object ‘a’.

Why must variables exist? Why can’t there be a Object#reference that
returns a reference to an object, so that:

a = b.reference

Makes a an ObjectReference that delegates to b.

Isn’t that in effect what Ruby does, since variables hold references
to objects? As in the classic case:

b = Hash[*%w{ one un two deux }]
a = b
a[“three”] = “trois”
p b[“three”] # => “trois”

David

···

On Wed, 17 Jul 2002, Dossy wrote:

On 2002.07.17, Dave Thomas Dave@PragmaticProgrammer.com wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav

Hal E. Fulton wrote:

In older versions of FORTRAN, there was a simple way of
doing just that – I forget how it worked – a COMMON
block or something? You could have a stored “constant” 1
and change it (say) to 2… upon which every 1 referenced
as a constant in the program would be changed to a 2
internally (since the compiler pooled its constants). So
a statement MYVAR = 1 would then assign the value 2 when
it was executed… amazing language, FORTRAN. Usually when
you’re given enough rope to hang yourself, you gain
flexibility and power as a benefit. Not in this case!

The ‘technique’ was called the literal pool. It was a nightmare to debug
especially with Fortran’s overlayed variables.

It does. In the attempt to make everything an object I also would
tend to think of namespace objects receiving something like
=(name, value) messages upon an assignment rather than of
shoebox objects.

Namespace objects could be a subset of bindings.

In the recent thread about “class local variables” as in

class A
a = 5
(…)
end

the class definition would have its own namespace with an entry for
the variable “a”. Method definitions and even blocks would have
their own namespace, too. The rules for block local variables and
the connection to lexically outer scope namespaces could be
made explicit in the implementation(s) of the namespace class(es).

Regards,
Pit

···

On 17 Jul 2002, at 14:54, Jim Weirich wrote:

I think that thinking of “a = b” as an assignment is the wrong way of
looking at it. Languages like FORTRAN, Pascal, and even C/C++ tend to
think of variables as shoeboxes into which you place a value. The
shoebox is a holder for the value.

Languages like Lisp have a different view. In Lisp, names are bound
to the values they represent. The name doesn’t reference a memory
location (i.e. shoebox) that can hold a value. The name is bound to a
value because there is a namespace (sometimes called an alist or
association list) that mentions the name and value together.

I have found it benificial to think of Ruby assignments to be more
like Lisp style name binding, rather than an C++ like assignment
statements. But I’m not sure I can articulate the reasons I find this
view better. Does this strike a chord with anyone else?

No, unfortunately, at least in ST-80 variables aren’t objects; they’re
just bindings.

There’s been some discussion on the Squeak list about making variables
into objects, though.

···

On Wednesday 17 July 2002 05:49 am, Dossy wrote:

Right. (IIRC, I believe Smalltalk also implements assignments as
message sends and everything is an object or a message as well.)


Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE

I assume run76 is a FORTRAN-76 compiler.

This was a pre-F76 version… F68? (I don’t
go back that far… it was obsolete even
when I was using it then, 1980 or so. Just
like most people are still using ksh88 now.)

I think all or most compilers allowed this
once upon a time.

Actually, I think this was so long ago it was not
considered a bug. Probably not even a feature.
More of a why-would-you-do-that-anyway.

Hal Fulton

···

----- Original Message -----
From: “Charles Hixson” charleshixsn@earthlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Tuesday, July 16, 2002 1:40 PM
Subject: Re: TkText no -textvariable workaround?

Was that run76, or was it FTN? Or did more than one Fortran compiler
have that bug?

I thought all “variables” were actually objects that lived in Dictionary
or somesuch.

Maybe I’m hallucinating all of this. You’re probably right: my
Smalltalk experience is very limited.

– Dossy

···

On 2002.07.18, Ned Konz ned@bike-nomad.com wrote:

On Wednesday 17 July 2002 05:49 am, Dossy wrote:

Right. (IIRC, I believe Smalltalk also implements assignments as
message sends and everything is an object or a message as well.)

No, unfortunately, at least in ST-80 variables aren’t objects; they’re
just bindings.

There’s been some discussion on the Squeak list about making variables
into objects, though.


Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)

I think all or most compilers allowed this
once upon a time.

> Actually, I think this was so long ago it was not 
> considered a bug. Probably not even a feature. 
> More of a why-would-you-do-that-anyway.

As I recall, it is because FORTRAN traditionally used
pass-by-reference semantics for passing variables to subroutines.
This allowed you to write …

  SUBROUTINE SET2(IVAR)
  IVAR = 2
  RETURN
  END

And use it like this …

  CALL SET2(J)

To set the variable J to the value 2. Unscrupulous programmers could
also do …

  CALL SET2(1)

Since the constant 1 was often stored in a particular memory location,
this would change the value stored at that location, so later
references to the literal 1 would really be the value 2.

Not all compilers had this (mis)feature, but it was a common artifact
of a fairly traditional FORTRAN implementation.

This reminds me of the ability in FORTH to define words
(i.e. subroutines to non-FORTHers) named with a literal number. The
number 1 was often defined as a word that pushes a literal 1 on the
stack (word references take a single cell while literals take two
cells in a tradition threaded code FORTH implementation). That meant
you could do things like this …

: 2 1 ; ( Define a word named “2” that returns the value 1 )

Of course, just because you could do that, doesn’t mean you should.

···


– Jim Weirich jweirich@one.net http://w3.one.net/~jweirich

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)