On Thu, 22 Oct 1998, Tyler Close wrote:
> > If you have something like:> > to foo(arg1, arg2) {> scope> }> > It seems to me that the above code actually instantiates a new object of> type foo with private data members arg1, arg2 and no methods.

That wasn't my understanding. You need to say "define" to define an
object; then you use "to" to define the methods of the object.

Also, it looks to me like you intend 'scope' to evaluate to the new
object. It actually returns a mapping of names to slots that
corresponds to the scope -- that is, by returning 'scope', you are
in fact exposing the 'arg1' and 'arg2' slots to the outside world.

> Therefore, if you had something like:> > to foo(arg1, arg2) {> to bar(arg) {> # bar this foo> }> scope> }> > I think this would instantiate a new object of type foo with private data> members arg1, arg2 and public method bar(arg).

As i had understood it up to this point, you would do what you've
described here by writing

The outermost 'define' evaluates to your new object (whose behaviour
is called 'foo'). That behaviour includes the private data members
'arg1' and 'arg2', and the public method 'bar(arg)'.

But this only makes you one object of this kind, and you could never
make another one.

If, as i suspect, you had intended this bit of code to create you a
new 'foo' using 'arg1' and 'arg2' as constructor arguments, you'd want:

define foo(arg1, arg2) {

define self {
to bar(arg) {
# bar this foo
}
}

}

The outer 'define' creates a maker object with one method named 'run'
which, when invoked, creates and returns an object that has 'arg1'
and 'arg2' in its scope and a method 'bar(arg)'. Now that you have a
maker you can call it as many times as you want to keep getting new
instance objects.

You don't need to "throw the object over the wall" the way you seem
to be doing with 'scope'. As long as the object definition is the
last thing to be completely evaluated, it will get returned.

Basically you've got it, except that you're using 'to' for both
objects and methods. In E as i understand it, 'to' is only used to
define methods and 'define' is for objects.

Instead of using 'define' for objects, i now see that you're using 'to'
for scoping and making functions, and then expecting 'scope' to make
you an object out of the current scope by turning functions on only
the current level of scope into methods on the object. It's an
interesting way of looking at it -- i think in fact it is isomorphic.

For the sake of a consistent understanding, i will describe the
translation. Tyler-E (if i may call it that) removes one level of
braces from E with a simple substitution that looks something like: