Article View: comp.lang.prolog
Article #2279Re: Trapping interrupts cleanly
From: Michael Dahmen
Date: Mon, 03 Jun 1991 07:16
Date: Mon, 03 Jun 1991 07:16
46 lines
2379 bytes
2379 bytes
> Article 3462 in comp.lang.prolog:
> From: popx@vax.ox.ac.uk (Jocelyn Paine)
> I'd be interested to know whether there are any Prologs that handle
> interrupts in a way that doesn't destroy functional purity.
> Now, I'm using Poplog Prolog. In this, you can nominate a predicate to
> be obeyed whenever CONTROL-C is typed. (For those who know Pop-11, you
> do so by assigning to the system procedure "interrupt"). But the only
> way to pass the State to the interrupt predicate is by doing something
> like
> mainloop( State ) :-
> read_command( C ),
> retractall( interrupt_goal(_) ),
> assert( interrupt_goal( mainloop(State) ),
> obey( C, State, NewState ),
> mainloop( NewState ).
> and arranging for the interrupt predicate to do
> interrupt_goal( G ),
> call( G ).
> The only other Prolog I've used extensively is ESL Prolog-2, and it
> doesn't provide any cleaner solution to this problem. Are there any
> Prologs that do? What is considered good style on those that don't?
I suggest to use a non-local exit construct (block/3, exit_block/1).
mainloop( State ) :-
read_command( C ),
block(obey( C, State, NewState ), abort, State = NewState),
mainloop( NewState ).
and arranging for the interrupt predicate to do
exit_block(abort).
I am not sure, but I think block/3 and exit_block/1 are part of the
proposed Prolog standard, and many Prolog implementation already
include them.
[Semantics: block(Goal, Tag, Recovery) calls Goal. If during evaluation
of Goal an exit_block(ExitTag) occurs, such that ExitTag and Tag unify,
then Recovery is called. Afterwards execution continues as if block/3
has been replaced by call(Recovery). If no exit_block/1 occurs, block/3
behaves like once(Goal).]
-- Michael Dahmen, ECRC, Munich
Technical Details
Message-ID:
<1991Jun3.071610.23645@ecrc.de>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!unido!ecrc!dahmenReferences:
<9105310922.AA22183@ucbvax.Berkeley.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!unido!ecrc!dahmen From: dahmen@ecrc.de (Michael Dahmen) Newsgroups: comp.lang.prolog Subject: Re: Trapping interrupts cleanly Message-ID: <1991Jun3.071610.23645@ecrc.de> Date: 3 Jun 91 07:16:10 GMT References: <9105310922.AA22183@ucbvax.Berkeley.EDU> Sender: news@ecrc.de Reply-To: dahmen@ecrc.de (Michael Dahmen) Organization: European Computer-Industry Research Centre, Munich Lines: 46