(eq? sym1 sym2) implementation
S D
s.mailinglists@gmail.com
Sat Mar 19 19:51:00 GMT 2005
I am wondering if the eq? operator should be implemented for symbols as follows
sym1 == sym2 ? true : (sym1.intern() == sym2.intern());
The reason is, I use the DOM parser and get the value of an attribute
which is returned from java as a java.lang.String which in kawa is a
symbol. So, now when I write code like
(case attribute-value
('val1 ...)
('val2 ...)
(else ...))
This didn't work and was always evaluating to the else part. After a
bit of investigation, I changed my (attribute-get node name) to
explicitly intern and return the attribute value and then it started
working as expected.
Given that two symbols if they are the same (no matter whether they
are hardcoded literals in the java code in which case they always
resolve to the same object or read through a file and hence a
different string object but captures the same string value) should
always return #t for eq? , would the above way of implementing eq? for
symbols a good idea as it removes the burden on the developer to
explicitly do the intern (which is error prone)?
More information about the Kawa
mailing list