I ran into a bug in ps::case (patch below). The trouble occurs when one of the keys that case is trying to match on is quoted:
(ps::ps-macroexpand '(case val ('a (b)))) => (SWITCH VAL (QUOTE) (A (B)))
This yields the following nonsensical js:
"switch (val) { case quote: case a: b();};"
A better macroexpansion would avoid processing the quoted form like a list, yielding:
(SWITCH VAL ('A (B)))
This doesn't produce any javascript, but rather an error:
(ps (case val '(a (b)))) => Cannot translate quoted value A to javascript [Condition of type SIMPLE-ERROR]
... which is the desired behavior, because PS always produces this error when encountering a quoted form it doesn't understand.
The reason this came up is that I'm building a specialized compiler on top of PS that handles quoted forms by turning them into strings. I've got this to work by means of :around methods on ps::compile-parenscript-form. But now the above bug with ps::case becomes a show-stopper because I need it to work with quoted keys (not just signal an error). I fixed it like so:
hunk ./src/special-forms.lisp 189 - (cond ((listp val) + (cond ((and (listp val) (not (eq (car val) 'quote)))
Could this fix please be added to PS?
Dan
Daniel Gackle wrote:
The reason this came up is that I'm building a specialized compiler on top of PS that handles quoted forms by turning them into strings. I've got this to work by means of :around methods on ps::compile-parenscript-form.
We may try at some point to do something smarter with quoted symbols in parenscript than simply throwing an error. Be sure to let us know about how your experiment works for you.
But now the above bug with ps::case becomes a show-stopper because I need it to work with quoted keys (not just signal an error). I fixed it like so:
hunk ./src/special-forms.lisp 189
(cond ((listp val)
(cond ((and (listp val) (not (eq (car val) 'quote)))
Could this fix please be added to PS?
It seems to me there may be room for a more general refactoring here, but in the meantime, your suggestion looks right to me. Applied.
Cheers,
-- Travis
parenscript-devel@common-lisp.net