Problem with macro with-timer

Philippe Brochard pbrochard at common-lisp.net
Tue Mar 4 15:41:47 UTC 2014


Andrea De Michele writes:

> I tried to call the macro with-timer like this:
>
> (with-timer (2) (focus-frame-by (find-frame-by-name "notification")))
>
> But sbcl give me the following error:
>
> The variable #:G1442 is unbound.
>
> If I call the macro with the optional parameter id like this all works:
>
> (with-timer (2 (gensym)) (focus-frame-by (find-frame-by-name "notification")))
>
> I think (but I'm not sure) that the problem is that the default value
> for the optional parameter id is evaluated before macroexpansion.
>
> If I change the definition of with-timer from:
>
> (defmacro with-timer ((delay &optional (id (gensym))) &body body)
>   "Same thing as add-timer but with syntaxic sugar"
>   `(add-timer ,delay
> 	      (lambda ()
> 		, at body)
> 	      ,id))
>
> to:
>
> (defmacro with-timer ((delay &optional (id '(gensym))) &body body)
>   "Same thing as add-timer but with syntaxic sugar"
>   `(add-timer ,delay
> 	      (lambda ()
> 		, at body)
> 	      ,id))
>
> both the way to call the macro (with and without the optional id parameters) works.
>
Hi, thanks for the report. You're right, the gensym is created only
once at compilation time. Your second version is the right thing to do
since a gensym is created each time we call add-timer.
The fix is applied in your name.

Regards,

Philippe



More information about the clfswm-devel mailing list