The story of E, part 2 (fwd)
Ka-Ping Yee
ping@lfw.org
Fri, 9 Oct 1998 04:35:26 -0700 (PDT)
The last of the forwarded correspondence. I will cc further replies
straight to this list.
Ping Talk back to the Web!
<ping@lfw.org> http://crit.org/
---------- Forwarded message ----------
Date: Fri, 09 Oct 1998 00:24:57 -0700
From: "Mark S. Miller" <markm@caplet.com>
To: Ka-Ping Yee <ping@lfw.org>
Subject: Re: The story of E, part 2 (fwd)
At 04:25 AM 10/8/98 -0700, Ka-Ping Yee wrote:
>If you don't mind the nitpicking... see
>http://crit.org/http://www.erights.org/ for my comments.
Thanks. Except for the color, these will be fixed with the next website
update. Care to suggest an alternate color?
>Well, i was very used to declaring data members explicitly
>and didn't have a feel for Scheme-like lexical scoping,
>so perhaps i belaboured the point more than you would feel
>necessary with the VectorMaker vs. AnotherVectorMaker example.
>Related to that is how an object's internals are safe from
>the outside.
No, not belabored at all. Most of my audience is unfamiliar with Scheme,
so this needs explaining.
>I have yet to grasp how to use "send" properly. I'll need
>to try it out some.
Absolutely!
>> (x*x + y*y) doubleValue sqrt
>
>Kind of yucky. How about toFloat? (like toString)
>...and toFoo for casting methods in general?
Wrt casting in general, I'm inclined against the "toFoo" approach because
it requires a named method per type you can cast to. Worse, it assumes a
globally understood binding between types and names. How about if
type-objects (including java classes) by convention are also coercers for
converting from nearby understood types. Waddaya think of
double coerce(x*x + y*y) sqrt
or even
double(x*x + y*y) sqrt
?
But ignoring the general coercion issue and concentrating on this case, I
like your suggestion but I think I like "as" better than "to":
(x*x + y*y) asDouble sqrt
Jeez I wish they hadn't defined "float" to mean "single precision IEEE
floating point"! I know of no remaining short word that simply means
"floating point" without specifying a precision.
>Oops. I need clarification on where scopes start. Is it
>all curly braces except right after "define ..." in the kernel
>language?
In the kernel language, yes, only the curlies of the object expression
encloses a behavior definition. In the full syntax, braces either enclose
a scoped expression, or they enclose a behavior definition, to be learned
on a case by case basis. Sorry, but nothing else seemed simpler. (Feel
free to take this as a challenge.)
>Hmm. I definitely think removing "hide" was the right thing to
>do ("var := hide { ... }" just doesn't read right), but i'd have to
>say that syntactic support for mappings would be very good to have.
Agreed on both counts.
>Well, i'm going to repeat my earlier proposal because i haven't
>thought of anything better yet:
>
> <1, 2, 3> for arrays
> ["a" => 440, "b" => 493, "c" => 523] for mappings
>
>I know that
>
> < 1, 2, 3 > - 4
>
>may look strange to a parser -- but you can simply declare the
>precedence so that the > matches with the < first, can't you?
I'm just not going to take the grammar into that kind of ambiguity-tempting
territory. Let's learn from C++'s mistakes and forget angle brackets. I'm
inclined to keep square brackets for tuples -- their visual rigidity is
appropriately suggestive. Similarly, I like curlies for mappings and sets.
Oh yeah, speaking of sets... In E, a set is simple a particular
convention for using a mapping: the members of the set are the keys of the
mapping, and all the values are null. My earlier mapping notation
supported this by considering
{"a", "b", "c"}
as shorthand for
{"a" => null, "b" => null, "c" => null}
Btw, if x and y are sets,
x & y is their intersection
x | y is their union
x - y is the elements of x not in y
x ^ y is the elements in exactly one of them, and
x <= y is true is x is a subset of y. (likewise with <, >=, and >)
These all have sensible meanings for x and y as general mappings (the x
value is dominant), but still has the simple meaning as applied to the
domain of the mapping. See
http://erights.org/doc/javadoc/org.erights.e.elib.tables.Mapping.html#or
So, with all that said, how about I break down and introduce the keyword
"set":
set {"a", "b", "c"}
has the obvious reading, while
set {"a" => 440, "b" => 493, "c" => 523}
still works because the best way to think of a mapping is as a set of
pairs. Btw, this latter will in turn be syntactic sugar for:
MappingImpl make([["a", 440], ["b", 493], ["c", 523]])
where, for example,
["a", 440]
will be sugar for
tupleMaker make("a", 440)
>You could then also do, for instance:
>
> @<1, 2, 3> for mutable arrays
> @["a" => 440, "b" => 493, "c" => 523] for mutable mappings
>
>or something like that.
>
>Hmmm... and about those method names...
>
> ? yourarray := @<1, 2, 3>
> # value: @<1, 2, 3>
>
> ? myarray := yourarray snapshot
> # value: <1, 2, 3>
>
> ? temparray := myarray scribble
> # value: @<1, 2, 3>
>
>Does "@" bear any resemblance to a scribble to you? Does
>"scribble" at all connote "taking a copy to scribble on" to you?
>
>I forget, do you use "@" in quasipatterns to denote a place
>to write things into?
I feel no need for special syntax for
newMutable/scribble/editcopy/editCopy, a good message name would be
sufficient. And you're right, "@" is reserved because of its use in
quasi-patterns.
>I think i could get used to it.
>
>Perhaps a little farfetched. But i couldn't think of any other
>word at the moment that means "to make a copy for private editing"...
>
>If you don't like "scribble", other short possibilities might
>be "mutable" or "mutate" or "edit" or "editcopy".
Well, it'd have to be "editCopy" or I would no longer have a memorable rule
for when to midcap. I think I like "editCopy", it's now tied for first
place with "newMutable". I would not have been able to guess what
"scribble" meant.
>By the way, does E do slices? What do you think of the following:
>
> ? list := <1,5,3,6,7>
> # value: <1, 5, 3, 6, 7>
? list := [1, 5, 3, 6, 7]
# value: [1, 5, 3, 6, 7]
> ? list[1:3]
> # value: <5, 3>
? list slice(1, 3)
# value: [5, 3]
See
http://erights.org/doc/javadoc/org.erights.e.elib.base.ArraySugar.html#slice
static methods of Sugar classes define, from E's point of view, instance
methods of the class they sugar. The first parameter of the static method
is the receiver, and the remaining parameters are the parameters of the
apparent instance method.
> ? list[:2]
> # value: <1, 5>
? list slice(0, 2)
# value: [1, 5]
> ? list[-1] # negative indices count from end
> # value: 7
Cute. I could generalize slice to do this, but in the meantime:
? list[list size -1]
# value: 7
> ? list[-3:] # get last three elements
> # value: <3, 6, 7>
? list slice(list size -3)
# value: [3, 6, 7]
> ? list := @<1,2,3,4,5>
> # value: @<1, 2, 3, 4, 5>
>
> ? list[1:4] := <8> # slice assignment accepts <> or @<>
> # value: <8>
>
> ? list
> # value: @<1, 8, 5>
Nothing like that in E. Do you find it a great convenience? Do you
actually use it? I understand why it's cool, but I don't think I'd want to
do it this way. (Ask me about Ropes sometime.) Here's a close & cleaner
(ie, side-effect free) version:
? list := list slice(0,1) + [8] + list slice(4)
# value: [1, 8, 5]
Since "list slice(0,1)" is statically known to the programmer to be a
single element, this particular case could have been written
? list := [list[0], 8] + list slice(4)
# value: [1, 8, 5]
>Oh, one last thing -- what is your distinction between 'string'
>and "string", if any -- and how do you interpret backslash-escapes?
It's like C or Java: 'c' defines a character. "str" defines a string.
Backslash escapes are precisely as in Java, which I think is the same as in
C or C++. OTOH, the escaping rules between quasi-quotes still needs work.
Cheers,
--MarkM
Btw, may I forward our correspondence to the E list?