This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: (eq? sym1 sym2) implementation


The behavior you're seeing is correct.  Kawa has both interned an
uninterned symbols as described in R5RS.  If you get a symbol (or
java.lang.String in your code) from a source that does not intern then
you're gonna have to intern it in order to get eq? to work for them.

I think it poor style to depend on this aspect of Kawa's implementation
(that symbols are j.l.String) and beware that it may break in the
future.  Also it would be rare/unexpected for the intern/eq? code to be
faster than using string=? (which does accept j.l.String) when the
number of cond clauses is not very large because intern has to do a fair
number of comparisons itself (it hashes to a bucket then does sequential
search).  Where interning is useful is when the symbols are interned on
read and then identity comparisons are done many times for each symbol,
not just once.

You can get the same coding style without unnecessary dependency (and no
interning) with case-equal (attached):

    (case-equal attribute-value
       ("val1" ...)
       ("val2" ...)
       (else ...))

Jim


(define-syntax case-equal
  (syntax-rules (else)
	((case-equal (key ...) clauses ...)
	 (let ((keyval (key ...)))
	   (case-equal keyval clauses ...)))
	((case-equal key (else result1 ...))
	 (begin result1 ...))
	((case-equal key ((values ...) result1 ...))
	 (if (member key '(values ...))
	     (begin result1 ...)))
	((case-equal key ((values ...) result1 ...) clauses ...)
	 (if (member key '(values ...))
	     (begin result1 ...)
	     (case-equal key clauses ...)))
	((case-equal key (value1 result1 ...))
	 (if (equal? key value1)
	     (begin result1  ...)))
	((case-equal key (value1 result1 ...) clauses ...)
	 (if (equal? key value1)
	     (begin result1  ...)
	     (case-equal key clauses ...)))
   ))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]