Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!gatech!udel!news.mathworks.com!news.kei.com!simtel!col.hp.com!news.corp.hp.com!isonews.bbn.hp.com!hpbbrd!jensk
From: jensk@hpbbn.bbn.hp.com (Jens Kilian)
Subject: Re: Converting code!!
Sender: news@hpbbrd.bbn.hp.com (News System)
Message-ID: <D789z2.3F5@hpbbrd.bbn.hp.com>
Date: Tue, 18 Apr 1995 11:16:13 GMT
References: <3m7e4t$9vj@homer.cs.mcgill.ca>
Organization: HP Mechanical Design Division
X-Newsreader: TIN [version 1.2 PL2]
X-Disclaimer: I do not speak for HP, I only *work* here.
Lines: 59

> Here is the code in Arity/Prolog

> rule_consult_epilog :-
> 	create(H, 'rules.out'),
> 	dup(H,1),
> 	output_goalpreds,
> 	listing(findaux/3),
> 	close(H),
> 	open(H1,con,w),
> 	dup(H1, 1).

> output_goalpreds :-
> 	recorded(rule_consulted,Atom, _),
> 	Goal =.. [Atom,Value,CF],
> 	assertz((findaux(Atom, Value, CF) :- Goal)),
> 	listing(Atom/2),
> 	nl,
> 	fail.

> output_goalpreds.

> Where as far as I can tell the two offending commands are :

> dup(X,Y) which assigns a second handle to an open file.

> create(Handle,FileSpec), which creates and opens an new file and returns
> 			the files handle.

This seems to be a Unix-ism.  The code fragment

	create(H, 'foo'),
	dup(H, 1)

redirects standard output to the file called 'foo'.  In Edinburgh Prolog,
this is what tell/1 does.  If you use an Edinburghish dialect, you'd write


	telling(CurrentOutput),
	tell('foo'),

	... output lots of stuff ...

	told,
	tell(CurrentOutput)

In standard Prolog, you would write

	current_output(CurrentOutput),
	open('foo', write, Stream),
	set_output(Stream),		% I'm not sure about the name here

	... output lots of stuff ...

	set_output(CurrentOutput),
	close(Stream)

Hope this helps,

	Jens.
