info-gnuprologjava
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Info-gnuprologjava] Adding hooks for executing code when frames are


From: Daniel Thomas
Subject: Re: [Info-gnuprologjava] Adding hooks for executing code when frames are being discarded
Date: Wed, 14 Dec 2011 09:40:29 +0000

On Wed, 2011-12-14 at 11:27 +1300, Matt Lilley wrote:
> Hello,
> 
> I'm trying to implement setup_call_cleanup/3 [1] in GNU Prolog for Java 
> so that I can port some code from SWI Prolog to GNU Prolog for Java.
> 
> For most cases, this is quite simple, but the case where the called goal 
> succeeds leaving backtrack points isn't possible at present (I think). 
> If you can see why, feel free to skip the next paragraph.
> 
> Consider setup_call_cleanup(true, member(A, [a,b,c]), throw(foo)), !. 
> After executing member(A, [a,b,c]), the interpreter pushes a backtrack 
> point. Then the ICut VM instruction is executed, which simply pops the 
> backtrack point off again, and then execution (of this goal, anyway) 
> stops - and throw(foo) isn't ever run. In order to execute the 
> throw(foo), I need to overload Interpreter.popBacktrackInfo (and similar 
> methods) to check for the cleanup-type goals and run them then. Adding 
> in an extra backtrack point won't work either, since we never actually 
> undo anything - we simply discard frames.
> 
> The simplest option from my perspective is to make Interpreter non-final 
> and make the constructor public. That would allow me to create my own 
> derived interpreter which could include such changes without causing 
> problems for anyone else. The second alternative would be to write code 
> to handle this and provide it back as a new standard feature of GNU 
> Prolog for Java, though since the predicate isn't ISO (as far as I 
> know), this might not be desirable for you. As a final point, I'd say 
> that although it might not be ISO, it's *extremely* useful!
> 
> Kind regards,
> Matt Lilley
> 
> [1] http://www.swi-prolog.org/pldoc/doc_for?object=setup_call_cleanup/3

Hello,

If you want to submit a patch to add that functionality then that would
be great, I have no problem with adding non-ISO features as long as ISO
features don't get broken and as long as it can be implemented cleanly.
Unfortunately I don't have time to work out how to write such a patch
myself at the moment but I do have time to review it. If you could add
some test cases to prove it works that would be great.

If implementing it cleanly is not possible then we can look at what
could be changed to either make that possible or to allow a local hack.

If you have any questions then please ask.

Best regards,

Daniel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]