Hi.
How to define a macro to give me this code:
(defun xhr-func () (setf (@ xhr onreadystatechange) (lambda () (if (= (@ xhr ready-state) 4) (progn (setf ime (@ xhr response-text)) (alert ime))) 0)) (chain xhr (open "GET" "/value.lisp" true)) (chain xhr (send null)))
I tried:
(defmacro xhr-macro () `(defun xhr-func () (setf (@ xhr onreadystatechange) (lambda () (if (= (@ xhr ready-state) 4) (progn (setf ime (@ xhr response-text)) (alert ime))) 0)) (chain xhr (open "GET" "/value.lisp" true)) (chain xhr (send null))))
Lispworks inserts lots of its code when trying macroexpand so it doesn't work. I would latter give arguments to the macro, ofcourse. What are defmacro/ps and defmacro+ps for ?
Thanks
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);"
You can use DEFMACRO in Parenscript code (in PS/PS*), or DEFPSMACRO in Lisp code, plus a few others to define and share macros between CL and Parenscript. There's further descriptions in the reference manual:
http://common-lisp.net/project/parenscript/reference.html#section-macros
Vladimir
On Fri, Apr 22, 2011 at 5:25 AM, Haris Bogdanovich fbogdanovic@xnet.hr wrote:
Hi.
How to define a macro to give me this code:
(defun xhr-func () (setf (@ xhr onreadystatechange) (lambda () (if (= (@ xhr ready-state) 4) (progn (setf ime (@ xhr response-text)) (alert ime))) 0)) (chain xhr (open "GET" "/value.lisp" true)) (chain xhr (send null)))
I tried:
(defmacro xhr-macro () `(defun xhr-func () (setf (@ xhr onreadystatechange) (lambda () (if (= (@ xhr ready-state) 4) (progn (setf ime (@ xhr response-text)) (alert ime))) 0)) (chain xhr (open "GET" "/value.lisp" true)) (chain xhr (send null))))
Lispworks inserts lots of its code when trying macroexpand so it doesn't work. I would latter give arguments to the macro, ofcourse. What are defmacro/ps and defmacro+ps for ?
Thanks
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net