christian at pflanze.mine.nu
Fri Oct 31 13:13:53 EDT 2008
Per Eckerdal wrote:
>> Ok, then my code is now rewritten as
>> (case (string->symbol ".ab") ((.ab) 1) (else 2))
> Keep in mind, though, that interned symbols are not garbage collected,
> so string->symbol with arbitary input might result in memory leaks.
For which there is a workaround here:
for those who didn't get this through irc support.
Anyway, a hash lookup will only outperform string=? if there are more
than just a couple of strings to compare. I.e.
(cond ((string=? foo ".ab") ..) (else ..)) will be faster.
And, once you're using a hash lookup anyway, there's no point using a
case statement which still does the linear search anyway. You could just
map the string to a thunk then.
((table-ref map the-key default-thunk))
More information about the Gambit-list