Speaking of Lisp...

Jeff Thompson jeff at thefirst.org
Fri Jan 5 17:01:46 PST 2007


P T Withington wrote:
>   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.

For Yield Prolog, I wrote my own internalize function.  (In Prolog, they call it an "atom".):

var _internalizedStrings = new Object();
// Return the unique string object that equals name.  If you always internalize the strings you use,
// then when you compare two strings, they will be the same string object and compare instantly.
function internalize(name) {
     var atomName = _internalizedStrings[name];
     if (atomName == undefined) {
         _internalizedStrings[name] = name;
         return name;
     }
     else
         return atomName;
}

This way, a string object itself is like a Lisp symbol, if you call internalize on it first.
Since Firefox 2.0, they fixed the following bug, so that == on two strings instantly checks
for two identical string objects.
https://bugzilla.mozilla.org/show_bug.cgi?id=314890

- Jeff




More information about the Es4-discuss mailing list