[Laszlo-dev] The one thing I really miss from Lisp is symbols

Max Carlson max at openlaszlo.org
Fri Jan 5 09:30:47 PST 2007


You might want to mention this on the es4-discuss-admin at mozilla.org list...

Henry Minsky wrote:
> Yeah I wish it was in the JSON reader, otherwise there's no way to do the
> interning automatically  unless you use eval.
> 
> On 1/5/07, P T Withington <ptw at openlaszlo.org> wrote:
>>
>> On 2007-01-05, at 10:32 EST, Henry Minsky wrote:
>>
>> > I was looking at a JSON (www.json.org) specification , and I
>> > realized one
>> > thing I miss in
>> > programming languages these days are symbols. JSON is pretty close
>> > to an
>> > s-expression except for
>> > the lack of symbols (except for the special cases of 'true',
>> > 'false', and
>> > 'null').
>> >
>> > None of the popular  scripting languages
>> > seem to have symbols. You'd think wth the interest in JSON that
>> > people might
>> > start wondering
>> > if there is some way to have built-in interned strings supported by
>> > their
>> > language...
>>
>> Well, 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 _ {
>>    static var allSymbols = {};
>>
>>    function _(name) {
>>      if (name in _.allSymbols) return _.allSymbols[name];
>>      this._name = name;
>>      return _.allSymbols[name] = this;
>>    }
>>
>>    function toString() {
>>      return this._name;
>>    }
>> }
>>
>> 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?
>>
>>
> 
> 


-- 
Regards,
Max Carlson
OpenLaszlo.org


More information about the Laszlo-dev mailing list