[E-Lang] E bug?
Mark S. Miller
markm@caplet.com
Sat, 20 Oct 2001 07:24:33 -0700
At 01:56 AM 10/20/2001 Saturday, steve jenson wrote:
>Scott Jaderholm and I were playing with Elmer earlier tonight and
>ran into the following issue:
>
>[In an Elmer session running 8.10alpha1]
>
>? class carMaker(name) :any {
>> var xLocation := 0
>> var yLocation := 0
>> def car {
>> to moveTo(x,y) {
>> xLocation := x
>> yLocation := y
>> }
>> to getX() :any {xLocation}
>> to getY() :any {yLocation}
>> to getName() :any {name}
>> }
>>}
># value: <carMaker>
>
>? def steveCar := carMaker("StevesCar")
># problem: [...]
>
>I pulled this code directly from E in a Walnut, so something tells me
>that this is incorrect behavior. Will somebody please hit me with the
>Brick of Knowledge(tm)?
The code in Walnut corresponding to your last line above is
def sportsCar := carMaker new("Ferrari")
so try
? def steveCar := carMaker new("StevesCar")
As it says later in Walnut, in the section 'Multiple Constructors and "Static Methods" ':
Under the covers, the passage "class carMaker(name) :any {...}" is
really a shorthand for defining a carMaker object with the single method
"new(name)".
Actually, this is oversimplified, but is the right was to think about it for
all purposes other than inheritance. The actual expansion of "class" is
given at http://www.erights.org/elang/blocks/inheritance.html . But if no
one calls carMaker's 'adopt' method, and if carMaker never uses the variable
'self' then this expansion is equivalent to the following fable:
class carMaker(args...) :guard {
...
}
can usually be thought to simply expand to
def carMaker {
to new(args...) :guard {
...
}
}
Cheers,
--MarkM