On Wed, Dec 22, 2010 at 11:56 AM, Mark S. Miller <erig...@google.com> wrote:
> On Tue, Dec 21, 2010 at 2:44 PM, Allen Wirfs-Brock <al...@wirfs-brock.com> > wrote: > >> >> Please don't totally disengage from the syntax discussion. Most >> programmers understanding of the language starts with the concrete (syntax) >> and then proceeds to the abstract (semantics). Syntax design can have a big >> impact on the usability of the underlying semantics >> > > > Ok, I am not sure what I think of the following idea, but it's a bit > different in flavor and so may stimulate other thoughts. I will express the > expansion in terms of the natural expansion for a soft fields underpinning. > One could do an equally natural expansion for private names. "==>" means > "expands to". Actual expansions would be a bit more complex to preserve the > left-to-right order of evaluation of the original. > > The basic idea is, since we're considering a sigil anyway, and since .# and > [# would both treat the thing to their right as something to be evaluated, > why not turn the sigil into an infix operator instead? Then it can be used > as "."-like "[]"-like without extra notation or being too closely confused > with "." or "[]" themselves. Finally, given the meaning of the sigil-turned > operator, "@" seemed to read better to me than "#". YMMV. > > > expr1 @ expr2 > ==> > expr2.get(expr1) > > expr1 @ expr2 = expr3; > ==> > expr2.set(expr1, expr3); > > const obj = {...@expr1: expr2, ...}; > ==> > const obj = {...}; expr1.set(obj, expr2); > > > Perhaps the expression on the right need not be a Name/SoftField. It could > be anything that responds to "get" and "set". > > Redoing the "class private" example at the end of http://wiki.ecmascript.org/doku.php?id=strawman:private_names#using_private_identifiers http://wiki.ecmascript.org/doku.php?id=strawman:names_vs_soft_fields#using_private_identifiers const key = SoftField(); // or, obviously, Name(), depending...function Thing() { this @ key = "class private value"; this.hasKey = function(x) { return x @ key === this @ key; }; this.getThingKey = function(x) { return x @ key; };} var thing1 = new Thing;var thing2 = new Thing; print("key" in thing1); // falseprint(thing1.hasKey(thing1)); // trueprint(thing1.hasKey(thing2)); // true -- Cheers, --MarkM
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss