On 5/14/11, Slobodan Milnović slobodan.milnovic@gmail.com wrote:
Hi!
I'm not sure what expressions/terms should I use for my situation, but I'll try my best to explain it.
I have several functions combined under one ps:ps, and I'd like to create different code depending on my, let's call it debug variable. I have tried something like this:
(ps:ps
(defun my-function (some-var) (ps:lisp (when (= my-debug-level debug-level-of-this-code) (ps:ps (ps:chain console (log "works!!!"))))) (generate some fancy regular javascript code)))
Unfortunatelly, when the inner ps does its thing, it creates an string, which then outer ps just attaches (and escapes appropriately) as string, not as additional javascript code that is to be attached to the rest. Is it possible to do this, or do I have to rethink my code?
I can only think of this alternative:
(defpsmacro conditional-splice (test &body body) (when test `(progn ,@body)))
Using an older parenscript, because I don't have HEAD handy (though I don't think it matters much, and you still get the general idea):
CL-USER> (ps:ps (progn (a 1) (conditional-splice t (b 1) (c 2) (d 3)) (e 2))) "a(1); b(1); c(2); d(3); e(2);" CL-USER> (ps:ps (progn (a 1) (conditional-splice nil (b 1) (c 2) (d 3)) (e 2))) "a(1); e(2);" CL-USER>
That should be easily adapted to your use case, though it seems different to me because the lisp evaluation now happens during "macroexpansion time". In parenscript, "macroexpansion time" is intertwined with compilation, so you can think of it as being the same as "compile-time".
(Please correct me if I'm wrong here).
Yong.