On Sat, Apr 25, 2009 at 12:02 PM, Daniel Gackle danielgackle@gmail.comwrote:
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).
What do you mean by "a runtime value?" In the current Parenscript keywords are compiled to the variable with the same name as the symbol. If you wanted a variable reference, you could replace a form like (foo :bar whiz) to (foo bar whiz).
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.
I am still confused about what functions this assumption is breaking, since quoted symbols are not translated into a JS equivalent. Can you provide a concrete example?
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.
The magic JSON object should be transparent to you when you define keyword arguments. That is, unless you are talking about a &rest or &keyword-object, both of which operate differently for parenscript functions than lisp functions.
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.)
This is a slick feature of Parenscript. Hopefully at some point we will see a full lisp -> javascript converter so that more code can be shared between client/server. Parenscript already does a lot more than any other solution out there for client/server code compatability (besides writing the server side in Javascript).
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
Agreed, for Parenscript. I would prefer true Lisp that compiles to Javascript, but I don't think that's what Parenscript should be.
-Red
On Sat, Apr 25, 2009 at 9:38 AM, Red Daly reddaly@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@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel