Re: JESS: Strange behaviour of defadvice
"Ernest Friedman-Hill" <[email protected]>
| Newsgroups | gmane.comp.java.jess |
|---|---|
| Message-ID | <[email protected]> |
Yes, a function can have only one advice. This wasn't originally the case, but experience showed that allowing multiple advice per function caused problems -- it was too easy to create infinite loops, for example. You can solve your problem with a before-advice which unbinds the variables, calls bsave explicitly, rebinds the variables, and then returns. If you check the documentation, it explains that explicitly returning from a before-advice will result in the adviced function not being called automatically. On Oct 7, 2010, at 8:44 AM, Gaëtan Pruvost wrote: > Hi everybody, > > I have a problem with defadvice's behavior. It looks like you can't > add both a "before" and an "after" advice to the same function. > Here is an example that demonstrates it > > (deffunction f () > (printout t "during f" crlf)) > > (defadvice before f (printout t "before f" crlf)) > (defadvice after f (printout t "after f" crlf)) > > (f) > > > It prints: > Jess> (batch "test.clp") > during f > after f > Jess> > > Looks like the after overwrote the before one and there is no way to > define both at the same time... > I'm new to Jess so I hope this question is not stupid but i looked > in documentation and in the old mailling-list messages and found no > explaination for it. Is it the intended behaviour (in which case it > would be good to precise it in the doc) or a bug? I'm using the last > Jess71p2. > > I needed this to unbind global variables before a bsave and rebind > after the bsave (this variable refers to a java Logger which is not > serializable). I've found another solution wihtout using defadvice > but I find the defadvice more elegant. > > > Best regards > -- > *********************************** > Gaëtan PRUVOST > > LIMSI-CNRS BP 133 > 91403 Orsay Cedex France > Tel:+33 1 69858110 > > http://www.limsi.fr/Individu/pruvost/ > *********************************** > <gaetan_pruvost.vcf> --------------------------------------------------------- Ernest Friedman-Hill Informatics & Decision Sciences, Sandia National Laboratories PO Box 969, MS 9012, Livermore, CA 94550 http://www.jessrules.com -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [email protected]' in the BODY of a message to [email protected], NOT to the list (use your own address!) List problems? Notify [email protected]. --------------------------------------------------------------------