Re: dynamic class idiom

2008-08-26 Thread Brendan Eich
On Aug 26, 2008, at 4:16 PM, Dave Herman wrote:

>> Does not say class, seems to save only a few chars (you
>> over-parenthesize new ;-). Wait for demand?
>
> It's not about saving chars so much as introducing a new (lightweight)
> semantic concept: an object initializer that is a block rather than a
> table mapping names to expressions. Not saying `class' is the point.

But you'd say class if you needed to define the operand to new for  
other uses, or for some other reason motivating against this  
"lightweight" form. So the concept seems to have two names when  
generalized slightly.

Specializations can have special names, don't get me wrong. But  
object is way overloaded.


> I over-parenthesized because I wasn't sure how it would parse if you
> said e.g.
>
>  new class() { ... }.foo

That should be unambiguous, and work as this does in ES1-3:

 new MyClass(arg).foo

The grammar goes to some lengths to group (new MyClass(arg)).


>>> or maybe to conserve keywords (a bit backwards-incompatible):
>>>
>>>  new { ... } ~=~ (new (class() { ... }))
>>
>> This is not incompatible at all, since an object initialiser has no
>> [[Construct]] in ES3, so cannot be the operand of new.
>
> Right, but that means that existing code isn't using this form, so you
> could steal this special case; then the argument to `new' would  
> have to
> be an expression that didn't start with '{', just like expression
> statements. It's backwards-incompatible but since the current syntax
> only leads to a useless error, I doubt real code is using it.

We consider such guaranteed errors to be unused, and call changes to  
claim the syntax backward-compatbile. At least we did in the ES4 WG.  
ES3 chapter 16 allows implementations to extend in this way, too.

/be

___
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: dynamic class idiom

2008-08-26 Thread Dave Herman
> Does not say class, seems to save only a few chars (you 
> over-parenthesize new ;-). Wait for demand?

It's not about saving chars so much as introducing a new (lightweight) 
semantic concept: an object initializer that is a block rather than a 
table mapping names to expressions. Not saying `class' is the point.

I over-parenthesized because I wasn't sure how it would parse if you 
said e.g.

 new class() { ... }.foo

>> or maybe to conserve keywords (a bit backwards-incompatible):
>>
>>  new { ... } ~=~ (new (class() { ... }))
> 
> This is not incompatible at all, since an object initialiser has no 
> [[Construct]] in ES3, so cannot be the operand of new.

Right, but that means that existing code isn't using this form, so you 
could steal this special case; then the argument to `new' would have to 
be an expression that didn't start with '{', just like expression 
statements. It's backwards-incompatible but since the current syntax 
only leads to a useless error, I doubt real code is using it.

Dave
___
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: dynamic class idiom

2008-08-26 Thread Brendan Eich
On Aug 26, 2008, at 2:49 PM, Dave Herman wrote:

> I noticed a little idiom supported by classes-as-values:
>
>  (new (class() { ... }))
>
> This essentially builds an object whose properties can be computed  
> in an
> arbitrary statement context-- with loops or what have you. You might
> call this a "dynamic singleton" pattern; a throwaway factory. It's  
> not a
> global singleton like in Java; it's just an ordinary expression so it
> might be called by a function or whatever.

Probably everyone involved favors first-class classes -- first-class  
meaning classes as values (not only as named defining forms),  
nestable. I hoped so in reply to Peter yesterday.


> Worth a little sugar? E.g.:
>
>  object { ... } ~=~ (new (class() { ... }))

Does not say class, seems to save only a few chars (you over- 
parenthesize new ;-). Wait for demand?


> or maybe to conserve keywords (a bit backwards-incompatible):
>
>  new { ... } ~=~ (new (class() { ... }))

This is not incompatible at all, since an object initialiser has no  
[[Construct]] in ES3, so cannot be the operand of new.

/be

___
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


dynamic class idiom

2008-08-26 Thread Dave Herman
I noticed a little idiom supported by classes-as-values:

 (new (class() { ... }))

This essentially builds an object whose properties can be computed in an 
arbitrary statement context-- with loops or what have you. You might 
call this a "dynamic singleton" pattern; a throwaway factory. It's not a 
global singleton like in Java; it's just an ordinary expression so it 
might be called by a function or whatever.

Worth a little sugar? E.g.:

 object { ... } ~=~ (new (class() { ... }))

or maybe to conserve keywords (a bit backwards-incompatible):

 new { ... } ~=~ (new (class() { ... }))

Dave
___
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


online es-decimal demo

2008-08-26 Thread Sam Ruby
http://code.intertwingly.net/demo/es-decimal/

user: brendan, password: cowlishaw

Instructions should be relatively self evident.  Enter a bunch of 
expressions, one per line.  Click submit.  See results.  Alter 
expressions.  Repeat.

Implementation notes:

This simply is a CGI that shells out to a version of SpiderMonkey with 
decimal support added.  This code is at an alpha level at best.  It may 
produce incorrect results.  It may trap.

I've tried SpiderMonkey with the -i parameter and capturing the results, 
but it seems to batch up the echoing of the input followed by all of the 
output.  So, for now, I'm simply wrapping each line in print(...); and 
passing the whole stream to the shell.  Yes, this makes testing of 
things like for loops difficult.  If anybody on this list has a 
suggestion, let me know.

Security notes:

Yes, I'm aware that many of you who follow this list know that what I'm 
providing is a dumb idea.  You know it.  I know it.  There is no need to 
show off.  But offline suggestions are welcome.

Availability:

 From time to time I will be updating this to the latest code.  If I get 
hacked (this host is not the one that serves my blog), the service will 
be taken down.  Eventually, I will be taking this down anyway.  But for 
now, feel free to play.

Testing cases:

What I'm really hoping for is test cases.  Find some output that is 
wrong and let me know.  I'm starting to build SpiderMonkey test cases, 
which ultimately are a simple matter of pairs of expressions and 
expected results.

http://code.intertwingly.net/public/hg/js-decimal/file/d65d970dd2ea/js/tests/decimal/ops/

- Sam Ruby


___
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Consistent decimal semantics

2008-08-26 Thread Igor Bukanov
2008/8/26 Brendan Eich <[EMAIL PROTECTED]>:
> Sam and I, not going in circles (much), agree that typeof 3m should
> be "object", and that we add hardwired operator support for such
> Decimal objects.

This would be very similar to QName and Namespace from E4X. typeof
returns "object" for both but there is special support for value
semantic in == and != operators for them so

  new Namespace("url") == new Namespace("url")

gives true. Also E4X leaves up to the implementation to decide what
should be the result of new Namespace("url") === new Namespace("url").

Regards, Igor
___
Es-discuss mailing list
Es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss