es-discuss Digest, Vol 106, Issue 46

Brendan Eich brendan.eich at gmail.com
Wed Dec 16 13:44:15 UTC 2015


`enum` has precedent -- C-like languages indeed use integers by default,
but see Rust for a generalized form:
https://doc.rust-lang.org/book/enums.html -- for a category-theory "sum"
type and IMHO handily beats `sym` or `sum`.

/be

On Wed, Dec 16, 2015 at 8:13 AM Coroutines <coroutines at gmail.com> wrote:

> On Wed, Dec 16, 2015 at 4:14 AM, John Gardner <gardnerjohng at gmail.com>
> wrote:
> > I do fully agree with the notion that enums should generate Symbols by
> > default... however, it seems unreasonable to prevent users from assigning
> > other types as well.
> >
> > Should enums also offer programmers the ability to assign explicit
> values,
> > as per traditional enum constructs? For instance, in TypeScript, coders
> are
> > able to assign values manually, or even elevate the initial index that
> > enumerations are counted from:
> >
> > const colours = {
> >     Red = 1,
> >     Green, //  2
> >     Blue  // 3
> > };
> >
> > We can probably do away with the initial index elevation (since enum'd
> names
> > would default to the Symbol representation of the identifier, anyway),
> but I
> > imagine many developers would expect to be able to assign integers in JS
> > enums the same way they can in C, et al.
>
> `enum` is probably the wrong keyword for the problem we're trying to
> solve by desugaring unique identifier declarations to Symbol creation.
> We're defining constants that should have no relation to each other.
> We're not enumerating anything as it's supposed to be a 'secret'
> Symbols are special globally defined integer identities behind the
> scenes.
>
> I'd personally add both?
>
> ```future-js-stuff
> sym RED, GREEN, BLUE;  # const RED = Symbol('RED')', GREEN =
> Symbol('GREEN'), BLUE = Symbol('BLUE');
> enum { RED: = 5, GREEN, BLUE }; # const RED = 5, GREEN = 6, BLUE = 7;
> ```
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20151216/84f8a392/attachment-0001.html>


More information about the es-discuss mailing list