[parenscript-devel] Keyword arguments and quoted symbols in Parenscript
Daniel Gackle
danielgackle at gmail.com
Sat Apr 25 19:02:52 UTC 2009
If I understand correctly, then yes, we object.
We have a lot of code that uses keywords as standalone values (e.g. tokens
in an AST), not keyword args to functions. It's important to have a way of
treating keywords that allows for both of these usages. In other words, a
keyword's presence in a lambda list might be (A) the name of a keyword arg
or (B) a regular old function arg (a runtime value). The trouble with the
old implementation of keyword args in PS is that it forced interpretation
(A) on all keywords in lambda lists, breaking a good many of our functions.
The code that's in PS right now supports both usages. It relies on the JS
"arguments" keyword to allow functions with keyword args to pick out the
dynamic portion of their lambda list without requiring them to be bundled
into a magic JSON object under-the-hood. That magic JSON object caused us
some trouble as well. We have a layer of our system written in a subset of
CL that we are able to compile into PS using macros. (This has critical
business value as it allows us to do some things which our competitors
cannot.) The magic JSON object created an impedance mismatch with Lisp that
made it impossible for us to write code in this subset that used keyword
args (we'd have to write a separate JS version to suck function args out of
the JSON object, which has no counterpart on the Lisp side). In general,
although I'm skeptical of attempts to make PS overly Lispy in ways that
don't have good equivalents in JS semantics, I also think that where there
are opportunities to align Lisp and PS semantics naturally, we should do so.
Daniel
On Sat, Apr 25, 2009 at 9:38 AM, Red Daly <reddaly at gmail.com> wrote:
> Hello ParenScripters,
>
> I have modified the behavior of keywords found in Parenscript source to be
> parsed into (PS-QUOTE keyword) instead of (JS-VARIABLE keyword). This seems
> to make more sense because in Lisp, evaluating a keyword yields the keyword
> itself rather than the value bound to it. As a result, the ability to paass
> keyword arguments to functions is now restored.
>
> CL-USER> (ps:ps (foo "bar" :quix "quo" :etc "etc..."))
> "foo('bar', { quix : 'quo', etc : 'etc...' });"
>
> Whereas this used to yield foo('bar', quix, 'quo', etc, 'etc...')
>
> In general, symbols occupy a strange place in Parenscript. Javascript has
> no analogue of Lisp symbols, so there is no sensible translation of symbols
> that works for everyone. Nonetheless, quoted symbols are used in many
> Parenscript macros to fake having real symbols in javascript. We could
> build in the ability to translate symbols to some javascript form, e.g.
>
> (ps:ps (make-instance 'animal)) => makeInstance( symbolTable["ANIMAL"] )
>
> The latter part of this post is just food for thought. I will go ahead and
> commit the patch for the former part of this post unless someone objects.
>
> Red
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20090425/6a7379d9/attachment.html>
More information about the parenscript-devel
mailing list