You can do that. It has a few downsides.
DEFMETHOD
andDEFGENERIC
are top-level forms. This means that the file compiler recognizes them and then knows about them. Inside aLET
, these forms are no longer top-level forms and the compiler does not recognize them.It makes debugging harder. Suddenly there is a context for methods.
It makes updating methods harder. I can't not just evaluate a
DEFMETHOD
form to update the method, I would also need to evaluate the context.
There are two typical ways to use a context at runtime:
- Use a dynamic binding at runtime
- Use a parameter at runtime
Example for 1:
(let ((*user* (find-current-user)))
(declare (special *user*))
(serve-page ...))
Alternatively the special variable could be declared global.
Example for 2:
(serve-page ... :user (find-current-user))
Even a plain package local variable can be good enough...