[parenscript-devel] create object doesn't accept symbols
Vladimir Sedach
vsedach at gmail.com
Sun Jul 29 18:48:43 UTC 2012
Hi Russell,
That makes sense. I pushed a patch that's similar to yours (I just
wanted to move the assert into the cond in that function).
Thank you for your contribution!
Vladimir
On Sat, Jun 2, 2012 at 3:27 AM, Russell Sim <russell.sim at gmail.com> wrote:
>
> Hey,
>
> I have hit another small bug while I was using some older code which was
> using quoted symbols as keys when defining an object. For example when
> I evaluate
>
> CL-USER> (ps:ps (ps:create 'test "bang" 'symbol-saved-my-life "parenscript"))
>
> I get the following error.
>
> Slot key 'TEST is not one of symbol, string or number.
> [Condition of type SIMPLE-ERROR]
>
>
> I have personally been using keywords instead of quoted symbols but it
> seems there was a time when quoted symbols were ok and the documentation
> seems to suggest that symbols should be fine?
>
> The following patch enables quoted symbols to work again and will
> convert them to the appropriate camelCase form.
>
> CL-USER> (ps:ps (ps:create 'test "bang" 'symbol-saved-my-life "parenscript"))
> "({ 'test' : 'bang', 'symbolSavedMyLife' : 'parenscript' });"
>
>
> Cheers,
> Russell
>
>
> commit 84d94815b1655179b283627a64bf6ed1ac1dba07 (HEAD, refs/heads/master)
> Author: Russell Sim <russell.sim at gmail.com>
> Date: Sat Jun 2 14:48:20 2012 +1000
>
> Allow quoted strings to be used as keys in objects
>
> Modified src/non-cl.lisp
> diff --git a/src/non-cl.lisp b/src/non-cl.lisp
> index f2ed0e7..5cba0a8 100644
> --- a/src/non-cl.lisp
> +++ b/src/non-cl.lisp
> @@ -52,12 +52,18 @@
> `(ps-js:object
> ,@(loop for (key val-expr) on arrows by #'cddr collecting
> (progn
> - (assert (or (stringp key) (numberp key) (symbolp key))
> - ()
> - "Slot key ~s is not one of symbol, string or number."
> - key)
> - (cons (aif (and (symbolp key) (reserved-symbol? key)) it key)
> - (compile-expression val-expr))))))
> + (assert (or (stringp key) (numberp key) (symbolp key) (eq 'quote (car key)))
> + ()
> + "Slot key ~s is not one of symbol, string or number."
> + key)
> + (cons (acond
> + ((and (symbolp key) (reserved-symbol? key))
> + it)
> + ((and (consp key) (eq 'quote (car key)))
> + (symbol-to-js-string (eval key)))
> + (t
> + key))
> + (compile-expression val-expr))))))
>
> (define-expression-operator %js-getprop (obj slot)
> (let ((expanded-slot (ps-macroexpand slot))
>
>
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
More information about the parenscript-devel
mailing list