defadvice ?
Opened this issue · 8 comments
First of all thank you for this great software !
I plan to integrate glisp as extension mechanism in one of my project.
I'll need the Advice [1] feature. Do you think this can be achievable ?
[1] - http://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html#Advising-Functions
Could you explain your use case? Adding this feature would require extensive code changes. From the man page you linked to, it seems like there are better ways of accomplishing something like what advice provides. Do you want to add hooks which run before built-in glisp functions?
Advice are AOP/Hook mechanism around not only built-in glisp function but also around user defined functions. The link I gave show the idea but a simpler version would be ok.
A simple example could be :
(defn foo [a b c d] (+ a b c d))
(defadv myadvice
(around foo
; if the first arg given to foo is positive then effectively call foo.
(cond (> (ad-get-arg 0) 0) ad-do-it )))
(adv-activate myadvice) ;to activate the advice
(foo 1 2 3 4) ; ok
(foo -4 9 8 7) ; ko
ad-do-it and adv-activate are special function and keywords.
for the definition of the advice before,after and around should be enough.
Hmm, I think that might complicate things. Would it be enough for me to add Before
and After
hooks in Go that get called around every Glisp function invocation? I think that is a more general solution. You can then implement something like defadvice
using those two hooks.
I understand your point, but the goal is that the user that will extends the program may not use go but glisp. It surely can be done via go but my users won't be able to extends behaviour without redefine everything.
Advices are common in lisp and other languages it bring natural power to the language. I'd understand if you choose not to implement it. In that case, I'll try a PR. Thank you.
If I add Before
and After
hooks in Go, you should be able to add your own code to allow the user to extend your methods from Lisp. I am somewhat loath to accept an "advice" feature into the core language. However, it is about time that I tackled adding a macro system, which would allow you to implement defadvice
yourself without modifying the core library.
Great to hear that. I agree that the hook system bring almost similar feature. Also I wait for the macro system. Thank you for your time.
Pre and Post function call hooks have been added in 461aec3. The pre hooks get passed environment, function name, and arguments. The post hooks get passed environment, function name, and return value. The main.go function has an example usage. I hope that this is satisfactory.
I'll check this out and keep you informed.