This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
(eq? sym1 sym2) implementation
- From: S D <s dot mailinglists at gmail dot com>
- To: kawa at sources dot redhat dot com
- Date: Sat, 19 Mar 2005 11:51:46 -0800
- Subject: (eq? sym1 sym2) implementation
- Reply-to: S D <s dot mailinglists at gmail dot com>
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)?