[comp.lang.prolog] Problem - interaction of consult/1 with see/1 and seen/0.

dave8@and.cs.liv.ac.uk (10/31/90)

I have run into a problem that occurs with the implementations of Prolog that
we have. When consulting, if see/1 and/or seen/0 is called inside the file
being consulted (yes, I actually wanted to do this in a test program!), the
Prolog concerned switches, after finishing with the directive in which
"see( File )" or "seen" occurs, to consulting "File" or "user" respectively.

Implementations which do this are C Prolog 1.5a and SB Prolog 3.1, and POPLOG
Prolog Version 11 for see/1, but this seems O.K. with seen/0 (however there
appear to be other problems with the behaviour of see/1 and seen/0 in POPLOG
Version 11).

The implementations that have this problem/annoying feature make use of
see/seeing/seen in the code for consulting, and that is where the problem
arises (at least in C Prolog, it is). They could be hacked so that consulting
does not make use of these (given that you have the source code).

The following programs, in three files, should demonstrate whether an
implementation has these problems or not - consult(seer1) and consult(seer2).       

------------------------------------------------------------------------------

% File:	seer1

:- write( 'Test whether use of see/1 affects consulting a file.' ) , nl , nl .

:-
  seeing( R )
, write( 'Currently seeing "' ) , write( R ) , write( '".' ) , nl
, File = 'seer.in'
, see( File )
, seeing( F )
, write( 'Now seeing "' ) , write( F ) , write( '".' ) , nl
, write( 'If you are back at the top level after the message' ) , nl
, write( '  In "' ) , write( F ) , write( '".' ) , nl
, write( 'your Prolog has the consult/see interaction problem/annoying feature.') , nl
, write( 'Issue "[ seer1 ] ." (again) to continue consulting this file.' ) , nl
.

:- write( 'This is the end of seer1.' ) , nl .

------------------------------------------------------------------------------

% File:	seer2

:- write( 'Test whether use of seen/0 affects consulting a file.' ) , nl , nl .

:-
  seeing( R )
, write( 'Currently seeing "' ) , write( R ) , write( '".' ) , nl
, File = 'seer.in'
, see( File )
, seen
, seeing( F )
, write( 'Now seeing "' ) , write( F ) , write( '".' ) , nl 
, write( 'If you get a "| " prompt (or in the case of SB Prolog, no prompt at all)' ) , nl
, write( 'your Prolog has the consult/seen interaction problem/annoying feature.') , nl
, write( 'Issue the directive ":- see( seer2 ) ." to continue consulting this file.' ) , nl
.

:- write( 'This is the end of seer2.' ) , nl .

------------------------------------------------------------------------------

% File:	seer.in

:- write( 'In "seer.in".' ) , nl .

------------------------------------------------------------------------------

Any comments?

Dave Sherratt		Probably dave8@uk.ac.liv.cs.and

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (11/01/90)

In article <1990Oct31.123459.3754@and.cs.liv.ac.uk>, dave8@and.cs.liv.ac.uk writes:
> I have run into a problem that occurs with the implementations of Prolog that
> we have. When consulting, if see/1 and/or seen/0 is called inside the file
> being consulted (yes, I actually wanted to do this in a test program!), the
> Prolog concerned switches, after finishing with the directive in which
> "see( File )" or "seen" occurs, to consulting "File" or "user" respectively.

Why does it surprise you when your system works?
Here's how seen/0 works:

	seen :-
		seeing(CurrentInput),
		see(user),
		close(CurrentInput).

(You may have been thinking of 'see' as a kind of 'push' and 'seen'
as a kind of 'pop'.  If you were, stop it at once.  It doesn't work
that way and never has.)

There _is_ a difference between Prolog systems:  in many Prolog systems
consult(File) makes File the current input, some (including Quintus) don't.
This really shouldn't make any difference to you, because the right way
to divert attention to some other file is

	seeing(OldInput),
	see(NewFile),
	/* do something that reads from NewFile */
	see(OldInput),		% make OldInput current again
	close(File)

or

	seeing(OldInput),
	see(NewFile),
	/* do something that reads from NewFile */
	seen,
	see(OldInput)

Either of those should work in any "Edinburgh-compatible" system.

-- 
The problem about real life is that moving one's knight to QB3
may always be replied to with a lob across the net.  --Alasdair Macintyre.