I'm implementing a small Lisp interpreter, which led me to discover this bug in the implementation of case:
(case "s"
'quote "quote"
"default")
;; Syntax error macroexpanding case at (org:localhost:56082(clj)*:131:16).
;; Duplicate case test constant: quote
I thought this might be a good workaround:
(case 'quote
(symbol "quote") "quote"
"default")
;; => "default"
This doesn't work, it returns "default".
Strangely, even though (symbol quote) would be invalid, since quote is not bound, THIS does "work" by returning "quote":
(case 'quote
(symbol quote) "quote"
"default")
;; => "quote"
Very weird. And look at this. Let's try a case of 'face. What will it return?
(case 'quote
'face "face"
"default")
;; => "face"
It matches 'quote!
Actually anything quoted matches:
(case 'quote
(quote 123) "123"
"default")
;; => "123"
Hopefully this will be enough for this to make sense to someone with knowledge of case's macroexpansion.
Cheers!