Dmitry Soshnikov dmitry.soshnikov at gmail.com
Thu Nov 17 09:47:15 PST 2011

On 17.11.2011 21:11, David Herman wrote:
> On Nov 17, 2011, at 6:41 AM, Dmitry Soshnikov wrote:
>> And uses `.extend' instance method (inherited from Object) for imperative delegation-based mixing.
> Sure, so that's just a method then, not an `extends` keyword.

Yep. And just a small note (to close the topic with Ruby): this 
`.extend' method is imperative form of the declarative version there 
which is done by `include' (keyword) operator and is used in classes:

module M
   def foo
     print "M.foo"

class A
   include M # module is mixed to the class
   def bar
     print "A.bar"

a = A.new
a.foo() # "M.foo"
a.bar() # "M.bar"

And using `.extend' objects (inc. classes) may the same mix modules to 
them. E.g.:


And all this is delegation-based (in fact, just adding another prototype 
for inheritance), but not copying of own properties.

Anyway, conclude with Ruby.

>> OK, though, I'd like again to notice Scala:
>> object foo extends bar {
>>    ...
>> }
>> class Foo extends bar {
>>    ...
>> }
> Right; in Scala it's still only part of a declaration syntax.

Yes, it's true, the form looks nice only with declarations. Seems it's 
not the best to pass it as an expression, e.g. creating intermediate 
object and passing it directly to a function. However with `with' it 
looks pretty nice:

(function (foo) {
})(obj with {x : 10})

>   Just in terms of being readable English, I don't think `extends` works as an operator. I think it only works as part of a declaration ("I declare that X extends Y"), or it would work as a boolean operator ("does X extend Y?"), but it doesn't work as an operator that creates a new object. You could do something like
>      extend X with Y
> but that would require a new reserved work `extend`. And it would be awkward to chain:
>      extend (extend X with Y) with Z

Yes, true. This is (unfortunately) only for declaration.

>> the same I proposed to ES (to avoid new keyword `object' I used simple `let' or `var'):
>> let foo extends bar {
>>    x: 100
>> }
> There are a number of things I don't like about this, but primarily the fact that it changes the uniform syntax of `let` or `var`.

And I primarily already don't like it (OK, not so like it ;)) because 
it's hard to use with expressions. "Only-declarations" protocol isn't 
the best.

>   Notice how Scala always uses a special prefix keyword that is built to work with `extends`.

It depends. Some programmers may claim Scala for abusing with many 
keywords. E.g. `var' and `val', which even can be hard distinguishable 
on some fonts for people with not so good vision, etc.

>> Thus, answering your mail (sorry for not answered before), I can't say, whether `extends' is infix or prefix. I don't completely understood on "can be conditional keywords", but what prevents `extends' to be the same?
> Oops, late night brain freeze. I meant to say "contextual keywords." When there's a grammar context that doesn't allow arbitrary identifiers, we can allow specific identifiers with custom meanings without them actually being reserved words. That's what we're doing for "of" in the for-of loop, and that's what we're doing for the "is" and "isnt" operators. They aren't reserved words.

It's interesting. I see.

(so it will be possible to do: var is = 10; and at the same time `obj is 
foo' ? OK.)

> But it doesn't work for prefix operators unless you use a reserved word. We have `extends` as a reserved word, so that works. But I don't like it for reasons of English, as I explained above (and in an earlier email).

I agreed on expressions as I said above. Well, if to introduce such an 
op, then perhaps `with' is better than new kw such as `beget', etc.


More information about the es-discuss mailing list