StopIteration, ForwardToTarget, ... & symbols
brendan at mozilla.org
Mon Nov 26 17:24:44 PST 2012
Allen Wirfs-Brock wrote:
> On Nov 26, 2012, at 1:11 PM, Brendan Eich wrote:
>> Herby Vojčík wrote:
>>> shouldn't StopIteration, ForwardToTarget from "Notification proxies" thread and similar ones be rather well-known unique symbols (like @iterator), now that we have them, instead of well-known globals? \
>> Let's separate the naming and unique identity concerns. Objects have unique identity, so do symbols. But if a unique identity is required without being a property key, then an object is the right answer, not a symbol. I think this applies to StopIteration.
>> Then there's the naming question. Should one have to use an @-name to reference a singleton object? Again I say no. APIs have public names, mostly or always. An identifier is a fine public name, better than a non-private symbol if bound in a namespace object or module -- or even if a global like JSON.
> Orthogonal issues. A symbol object object can be the value bound to a regular identifier. The @ is primarily for literal property naming syntactic contexts. EG, after a dot.
I know it's orthogonal -- please!
It was not clear which of the two (or both) Herby was raising.
>>> On the more general line, I got pretty fond of (unique) symbols, they seem like very good things for these sentinel-like objects. Is it ok / preferable to use them for that? No need to use empty objects bearing only their identity any more, imo.
>> For unique identity, why do you care between symbol and object?
> A nice thing about Symbols as I've now spec'ed them in the latest draft. It that they are truly immutable, stateless, and Realm independent. They don't carry any other object references at all. Not even to their toString method. (fun things that can be done via the MOP...)
The realm independence is interesting. That could be compelling indeed
for StopIteration, except we already proposed isStopIteration.
More information about the es-discuss