I have some test data where occasionally an empty list appears as an element inside of some other list. It's getting compiled to the JS string "[]" when what I need is the array literal [], in a way that seems inconsistent.
Specifically, these are good:
PS> (ps []) "[];"
PS> (ps '()) "[];"
PS> (ps '(1 2)) "[1, 2];"
But these are not, because they generate either the string '[]' or null as the second element, when what I need is the array literal []:
PS> (ps '(1 [])) "[1, '[]'];"
PS> (ps '(1 ())) "[1, null];"
Is this an inconsistency? Is there a workaround?
Daniel
Hi Dan,
PS> (ps '(1 [])) "[1, '[]'];"
That is indeed weird. I fixed it by treading [] as a special case (like a single-quoted nil). The patch is in the repository.
PS> (ps '(1 ())) "[1, null];"
Now this is not weird, because the base case here is '(()) aka '(nil). This is the unfortunate side effect of CL treating () and nil equivalently and Parenscript treating () and [] equivalently. There's no way to tell from the context which is the "right" way to compile '(()). I think it is more consistent to have '(()) compile to [null] rather than [[]], but I am open to hearing other options.
Vladimir
parenscript-devel@common-lisp.net