Speaking of Lisp...

Bob Ippolito bob at redivi.com
Fri Jan 5 16:04:42 PST 2007


On 1/5/07, P T Withington <ptw at pobox.com> wrote:
> One of our developers wondered why no scripting language has adopted
> symbols.  I replied:
>
> > Objects have most of the features of symbols:  they are unique, you
> > can compare them for identity, you can store properties on them.
> > An object by itself is like an uninterned symbol -- you have to
> > keep a handle on it.  If you want to intern an object, you can just
> > assign it to a global variable.  So, I think what you are mostly
> > missing is the shorthand where in lisp you can write
> > 
> >   'foo
> >
> > and if the symbol already exists, you get the symbol, and if it
> > doesn't it will be created for you.
> >
> > It wouldn't take much to mimic that in Javascript.  Something like:
> >
> > class Symbol {
> >   static var allSymbols = {};
> >
> >   function Symbol(name) {
> >     if (name in Symbol.allSymbols) return Symbol.allSymbols[name];
> >     this._name = name;
> >     return Symbol.allSymbols[name] = this;
> >   }
> >
> >   function toString() {
> >     return this._name;
> >   }
> > }
> >
> > var _ = Symbol;
> >
> > Then you can write a symbol as:
> >
> >   _('mySymbol')
> >
> > Clearly, IWBNI there were a shorter hand for writing symbol
> > literals, 1 character rather than 5, but this isn't too bad is it?
>
> Were symbols ever discussed as a possible addition?  Is there a handy
> non-symbol punctuation mark that could be co-opted?
>
>    @mySymbol
>
> Dylan uses:
>
>    #"mySymbol"
>
> (3 characters rather than 5).  Yet another use for `#`.

Do you think that encouraging global variables would be a good thing?
I thought ES4 was trying to make them less popular.

-bob




More information about the Es4-discuss mailing list