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: http://scheme.ch/gambit/preview/cj-symbol.scm (and http://scheme.ch/gambit/preview/cj-symbol-module.scm)
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))
Christian.