Hello,
I have a problem with the Parenscript from the latest Quicklisp update (2012-02-08).
Before this update: I'm trying to instantiate an object using 'new'. Since I wanted to have 'var obj = new ClassName();' and not 'var obj = new ClassName' I used '(ps ((new -class-name)))' which did what I wanted (generate 'new ClassName()').
After the update: '(ps ((new -class-name)))' generates '(new ClassName)()' which is wrong. Luckily for me, 'new ClassName' generated by '(new -class-name)' works.
What do I do if I need to generate something like 'new Person(age, shoeSize)'? (i.e. I don't know how to pass parameters to new - and I could not find a description of any special syntax in the manual). '(ps (new -person age shoe-size))', fails with an error which seems to imply that there can be only one argument to new (when printing :-) ).
I managed to convince the printer to accept '(ps (new -person age shoe-size))' and generate 'new Person(age, shoeSize)' using the code in this patch:
diff --git a/src/printer.lisp b/src/printer.lisp index c37e10c..d7e26f4 100644 --- a/src/printer.lisp +++ b/src/printer.lisp @@ -235,7 +235,14 @@ vice-versa.") (defprinter ps-js:negate (x) "-"(print-op-argument op x))
-(defprinter (ps-js:delete ps-js:typeof ps-js:new ps-js:throw) (x) +(defprinter ps-js:new (&rest x) + "new " + (ps-print (car x)) + "(" + (psw (format nil "~{~a~^, ~}" (mapcar #'symbol-to-js-string (cdr x)))) + ")") + +(defprinter (ps-js:delete ps-js:typeof ps-js:throw) (x) (print-op op)" "(print-op-argument op x))
(defprinter (ps-js:return) (&optional (x nil x?))
Thanks for any suggestions,
(ps (new (Person age shoe-size))) outputs new Person(age, shoeSize)
This brings up a good point about the syntax of 'new'. Maybe the above is not a good way?
In any case, I've written up a description of how 'new' works now in the reference manual (http://common-lisp.net/project/parenscript/reference.html).
Vladimir
On Sat, Feb 11, 2012 at 2:36 AM, Miron Brezuleanu mbrezu@gmail.com wrote:
Hello,
I have a problem with the Parenscript from the latest Quicklisp update (2012-02-08).
Before this update: I'm trying to instantiate an object using 'new'. Since I wanted to have 'var obj = new ClassName();' and not 'var obj = new ClassName' I used '(ps ((new -class-name)))' which did what I wanted (generate 'new ClassName()').
After the update: '(ps ((new -class-name)))' generates '(new ClassName)()' which is wrong. Luckily for me, 'new ClassName' generated by '(new -class-name)' works.
What do I do if I need to generate something like 'new Person(age, shoeSize)'? (i.e. I don't know how to pass parameters to new - and I could not find a description of any special syntax in the manual). '(ps (new -person age shoe-size))', fails with an error which seems to imply that there can be only one argument to new (when printing :-) ).
I managed to convince the printer to accept '(ps (new -person age shoe-size))' and generate 'new Person(age, shoeSize)' using the code in this patch:
diff --git a/src/printer.lisp b/src/printer.lisp index c37e10c..d7e26f4 100644 --- a/src/printer.lisp +++ b/src/printer.lisp @@ -235,7 +235,14 @@ vice-versa.") (defprinter ps-js:negate (x) "-"(print-op-argument op x))
-(defprinter (ps-js:delete ps-js:typeof ps-js:new ps-js:throw) (x) +(defprinter ps-js:new (&rest x)
- "new "
- (ps-print (car x))
- "("
- (psw (format nil "~{~a~^, ~}" (mapcar #'symbol-to-js-string (cdr x))))
- ")")
+(defprinter (ps-js:delete ps-js:typeof ps-js:throw) (x) (print-op op)" "(print-op-argument op x))
(defprinter (ps-js:return) (&optional (x nil x?))
Thanks for any suggestions,
Miron Brezuleanu
parenscript-devel mailing list parenscript-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
On Tue, Feb 14, 2012 at 1:04 AM, Vladimir Sedach vsedach@gmail.com wrote:
(ps (new (Person age shoe-size))) outputs new Person(age, shoeSize)
This brings up a good point about the syntax of 'new'. Maybe the above is not a good way?
In any case, I've written up a description of how 'new' works now in the reference manual (http://common-lisp.net/project/parenscript/reference.html).
Thanks for the information! The existing syntax is OK by me, the only bug was the lack of documentation, which is now fixed. I think changing the syntax would break a lot of code and give people trouble without good reason.
One nitpick: with READTABLE-CASE set to :UPCASE the example in the manual should read '(new (-person age shoe-size))' - or am I missing something else?
Thank you again,
Yes, it really should, but I want to encourage people to change their readtables to invert.
On Tue, Feb 14, 2012 at 8:04 AM, Miron Brezuleanu mbrezu@gmail.com wrote:
On Tue, Feb 14, 2012 at 1:04 AM, Vladimir Sedach vsedach@gmail.com wrote:
(ps (new (Person age shoe-size))) outputs new Person(age, shoeSize)
This brings up a good point about the syntax of 'new'. Maybe the above is not a good way?
In any case, I've written up a description of how 'new' works now in the reference manual (http://common-lisp.net/project/parenscript/reference.html).
Thanks for the information! The existing syntax is OK by me, the only bug was the lack of documentation, which is now fixed. I think changing the syntax would break a lot of code and give people trouble without good reason.
One nitpick: with READTABLE-CASE set to :UPCASE the example in the manual should read '(new (-person age shoe-size))' - or am I missing something else?
Thank you again,
-- Miron Brezuleanu
parenscript-devel mailing list parenscript-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
On Wed, Feb 15, 2012 at 12:27 AM, Vladimir Sedach vsedach@gmail.com wrote:
Yes, it really should, but I want to encourage people to change their readtables to invert.
Well, someone who knows about Parenscript symbol name rendering to JavaScript and READTABLE-CASE will know what this is about. Someone new to either Parenscript or Common Lisp will have some trouble figuring things out or will report a bug. If you don't want to change the example to work with :UPCASE, maybe putting a note about READTABLE-CASE in the 'new' section would be useful? (converting the whole manual to one style or another and mentioning the assumed READTABLE-CASE in the 'Symbol Conversion' section is better, but also a great deal of work).
For me personally, changing READTABLE-CASE to :INVERT is not a good choice. I like 'shoe-size' better than 'shoeSize' - it looks more readable to me. On the other hand, there's some pain when writing things like 'JSON.stringify' :-)
Maybe Parenscript should include a (not automatically installed) reader macro that temporarily switches READTABLE-CASE to :INVERT for the next symbol? (again, for me personally, that would be best: having both 'shoe-size' and an easy way to enter 'JSON.stringify').
Actually, foo-bar works perfectly fine with :invert so everything is backward compatible. Parenscript doesn't know anything about readtables, just when a symbol name is mixed-case.
The one case where this is ambiguous is something like Foo-bar, which right now gets translated as fooBar.
Vladimir
On Wed, Feb 15, 2012 at 3:07 AM, Miron Brezuleanu mbrezu@gmail.com wrote:
On Wed, Feb 15, 2012 at 12:27 AM, Vladimir Sedach vsedach@gmail.com wrote:
Yes, it really should, but I want to encourage people to change their readtables to invert.
Well, someone who knows about Parenscript symbol name rendering to JavaScript and READTABLE-CASE will know what this is about. Someone new to either Parenscript or Common Lisp will have some trouble figuring things out or will report a bug. If you don't want to change the example to work with :UPCASE, maybe putting a note about READTABLE-CASE in the 'new' section would be useful? (converting the whole manual to one style or another and mentioning the assumed READTABLE-CASE in the 'Symbol Conversion' section is better, but also a great deal of work).
For me personally, changing READTABLE-CASE to :INVERT is not a good choice. I like 'shoe-size' better than 'shoeSize' - it looks more readable to me. On the other hand, there's some pain when writing things like 'JSON.stringify' :-)
Maybe Parenscript should include a (not automatically installed) reader macro that temporarily switches READTABLE-CASE to :INVERT for the next symbol? (again, for me personally, that would be best: having both 'shoe-size' and an easy way to enter 'JSON.stringify').
-- Miron Brezuleanu
parenscript-devel mailing list parenscript-devel@common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net