[parenscript-devel] macro

Alex Mizrahi alex.mizrahi at gmail.com
Fri Apr 22 10:19:47 UTC 2011


 HB> I tried:

 HB> (defmacro xhr-macro ()
 HB>   `(defun xhr-func ()
 HB>      (setf (@ xhr onreadystatechange) (lambda ()
 HB>                                         (if (= (@ xhr ready-state) 4)
 HB>                                           (progn
 HB>                                        (setf ime (@ xhr response-text))
 HB>                                             (alert ime)))
 HB>                                         0))
 HB>      (chain xhr (open "GET" "/value.lisp" true))
 HB>      (chain xhr (send null))))

 HB> Lispworks inserts lots of its code when trying macroexpand
 HB> so it doesn't work.
 HB> I would latter give arguments to the macro, ofcourse.
 HB> What are defmacro/ps and defmacro+ps for ?

I think defpsmacro is exactly what you need -- you define macro in Lisp code 
using defpsmacro (like you did above with defmacro but with defpsmacro 
instead of defmacro) and then you can use it anywhere in your PS code.

You do not need macroexpand to test your macro, to see what code it 
generates just use ps:ps.
E.g.

(ps:defpsmacro foo (xxx) `(frob, xxx))

(ps:ps (foo xxx))
=> "frob(xxx);"





More information about the parenscript-devel mailing list