users-prolog
[Top][All Lists]
Advanced

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

Re: streams


From: A-S Saidi
Subject: Re: streams
Date: Mon, 05 Sep 2005 16:05:45 +0200
User-agent: Mozilla Thunderbird 1.0.2 (X11/20050317)

Hi,
Gonna give youthe answer I got some time ago (the same question !).
Things work by the solution (1) but more generaly by (2).

Regards.

Alexandre.

______________________________________________________________
1-
.... Here is what I did (essentially your example but in two steps):

Best regards,
Johannes


$ gprolog
GNU Prolog 1.2.18
By Daniel Diaz
Copyright (C) 1999-2004 Daniel Diaz
| ?- [user].
compiling user for byte code...
entier(0).
entier(succ(N)) :- entier(N).

user compiled, 3 lines read - 348 bytes written, 8476 ms

(1 ms) yes
| ?- open(fichier,write,F), current_input(I), current_output(O),
     asserta(streams(F,I,O)),
     '$set_top_level_streams'(I, F),entier(succ(succ(0))).
| ?- retract(streams(F,I,O)),
     '$set_top_level_streams'(I, O), close(F).

F = '$stream'(2)
I = '$stream'(0)
O = '$stream'(1)

(1 ms) yes
| ?- halt.

$ cat fichier 

F = '$stream'(2)
I = '$stream'(0)
O = '$stream'(1)

yes
$

___________________________________________________________
2- via script cpmmand :
Following my question about "stdout redirection in Gprolog", Gurvan Le Guernic gave a general
 answer ("script" command under Unix/Linux) that did the job.
I post it hereby.

This works not only for Gprolog but also for any command.
In order to gather (to mirror) outputs,  launch " script -c gprolog myfile" and "myfile" is a mirrir of the stdout :
(see "man script" also).

Here's an example (sorry for Windoz users !):
---------------------------------------------------------

address@hidden:> script -c gprolog toto
Le script a débuté, le fichier est toto
GNU Prolog 1.2.16
By Daniel Diaz
Copyright (C) 1999-2002 Daniel Diaz
| ?- write(1).
1

yes
| ?- listing.

yes
.......................

| ?- halt.

Script complélé, le fichier est toto
address@hidden:>

address@hidden:> cat toto
Le script a débuté sur mar 01 mar 2005 19:58:00 CET
GNU Prolog 1.2.16
By Daniel Diaz
Copyright (C) 1999-2002 Daniel Diaz
| ?- write(1).
1

yes
| ?- listing.

yes
.....................
| ?- halt.
Script complété sur mar 01 mar 2005 19:58:10 CET
---------------------------------


Cliff Bender a écrit :
Hi,

I'd like some help trying to understand the use of streams. As I understand, this should produce a file 'out.txt', with the listing in it. However, the listing gets printed to the screen, and the file is empty:

| ?- open('out.txt', write, H, [alias(out)]), current_output(COUT), set_output(out), listing, set_output(COUT).

squint([], []).
squint([A|B], [C|D]) :-
        integer(A),
        C is A * A,
        squint(B, D).
squint([A|B], [A|C]) :-
        squint(B, C).

COUT = '$stream'(1)
H = '$stream'(2)

(1 ms) yes
| ?-


If anyone has any ideas, suggestions, anything, please reply.
Thanks and have a great weekend.
Cliff



_______________________________________________ Users-prolog mailing list address@hidden http://lists.gnu.org/mailman/listinfo/users-prolog

-- 
Aleksander S. Saidi
Ecole Centrale de Lyon
Département Mathématiques-Informatique
Mél : address@hidden
Tél : 04.72.18.65.30, Fax : 04.78.33.16.15

Attachment: Alexandre.Saidi.vcf
Description: Vcard


reply via email to

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