[parenscript-devel] How to call constructor?

Vladimir Sedach vsedach at gmail.com
Mon Feb 13 23:04:05 UTC 2012


(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 at 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 at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel




More information about the parenscript-devel mailing list