a question of Char(acter) (breaking change)

68 views
Skip to first unread message

dmiller2718

unread,
Apr 17, 2022, 4:31:54 PM4/17/22
to clojure-clr
Just a heads up on a breaking change as ClojureCLR is about to go beta on 1.11.

The change is in response to the problem noted in  issue CLJCLR-112 (https://clojure.atlassian.net/browse/CLJCLR-112).

The symptom:
Recall that the apostrophe character numerically is 39.

user=> (hash-map 39 0 \' 1)
{39 0, \' 1}
user=> (assoc {39 0} \' 1)
{39 1}
user=> {39 0, \' 1}
Syntax error reading source at (REPL:27:13).
Duplicate key: 39


ClojureJVM does what you would hope with these.

The root cause comes down to a regrettable decision I made about 12 years ago.  I well remember contemplating it.

The decision: I classified Char as a numeric type.

My thinking at the time was that because C# had implicit conversions for Char, effectively the type acted that way.

In ClojureJVM, the code for handling arithmetic operations is based on the abstract class java.lang.Number (https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html) which has no equivalent in CLR-land.  So I faked it.  But not well enough, apparently.

The simplest way to get map keys to work as desired is just to change the designation fo Char to be non-numeric.  I think it has almost no other consequences.  But if it is a concern, please check it out when the beta of 1.11 comes out.

BTW, ClojureCLR's behavior is still not an exact match.  Eval'ing (+ 1 \a ) will work in ClojureCLR (giving an integer result), but not in ClojureJVM.  In the latter,  it fails because Character is not derived from Number.  There is no easy way to get the same behavior in ClojureCLR, at least nothing I think is worth the effort at this time.





Reply all
Reply to author
Forward
0 new messages