chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] symbol->string


From: Thomas Chust
Subject: Re: [Chicken-users] symbol->string
Date: Mon, 23 Oct 2006 11:14:27 +0200 (CEST)

On Mon, 23 Oct 2006, address@hidden wrote:

[...] I looked at the definition of symbol->string and found out that it is not a constant operation (like returning some pointer) but constructs a string. Does anyone have a more efficient comparison of symbols implemented? [...]

Hello,

as far as I know, symbols with identical names are always pointer equal in CHICKEN unless one of them has been created using gensym, so if you just need equality comparisons, eq? will be the fastest option.

If you want alphabetic ordering, you should avoid symbol->string, because it copies the name of the symbol to a new string -- this is necessary as Scheme's strings are mutable objects! I would suggest accessing the name slot of the symbol directly and defining

   (define (symbol-compare a b)
     (##sys#check-symbol a 'symbol-compare)
     (##sys#check-symbol b 'symbol-compare)
     (string-compare (##sys#slot a 1) (##sys#slot b 1)))

I hope that helps,
Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]