cl-cookbook icon indicating copy to clipboard operation
cl-cookbook copied to clipboard

advise and watch really exist in sbcl?

Open bo-tato opened this issue 1 year ago • 2 comments

Thanks for the cookbook it is an awesome resource. In the section on debugging under advise and watch it says:

They do exist in SBCL but are not exported.

That would be really great as being able to set a watch on some variable and breaking when it's modified is the one thing I miss from emacs lisp. I can't find anything else on this searching online, or searching the whole sbcl source code for "advise" and "watch".

bo-tato avatar Jul 25 '23 23:07 bo-tato

ah yes, I miss it too. I actually saw that here: https://github.com/lisp-mirror/budden-tools/tree/213ab2b52a1b0c0b496efd30c3b5143f5c8e1ff2/cl-advice It "used to work on SBCL 1.4.2".

here they say

An advise-like mechanism has to be present in any CL implementation in order to support trace; it just isn't necessarily exposed.

vindarel avatar Jul 26 '23 12:07 vindarel

great info, thanks! from that reddit link the same user notes you can implement advice yourself in ordinary common lisp without any special help from the implementation:

You can put a new function into a function binding with (set (symbol-function ) ). Your new function can call the old one (which you can keep in some table keyed on whatever), and do things around it. That is called "advice". Then later you can restore the old one. All of this can be done portably, and with compiled functions.

It seems that cl-advice library is calling sb-int:encapsulate, which is still present in latest SBCL, it seems internally SBCL calls advise/unadvise encapsulate/unencapsulate and is defined in src/code/fdefinition.lisp. Still there is no watch in SBCL?

bo-tato avatar Jul 26 '23 16:07 bo-tato