Dear CIAO Users
I tried to run the following program in CIAO v1.6
------------------------------------------------------ :- op(950,xfx,'==>').
:- use_module(library(read)). :- use_module(library(write)).
main :- open('file.pl',read,Stream), read(Stream,A), close(Stream), write(A), nl. ------------------------------------------------------
where the contents of "file.pl" are:
p(a==>b).
and I got the following:
[user(a)thurso]$ ciao Ciao-Prolog 1.6 #1: Thu Aug 3 11:19:43 BST 2000 ?- ensure_loaded(program).
yes ?- main. {ERROR: read/2 - syntax error (lns 1-1) , or ) expected in arguments: p ( a ** here ** ==> b ) . }
no ?- halt. ----------------------------------------------------
I ran the same program on SICStus (commenting out the use_ module lines) and it worked OK.
What is going on here? Is there anything I should be doing?
Thanks for any help in advance
Cheers
-- wamberto
Dear Wamberto,
In Ciao, unlike in SICStus, there is a clear separation between compile-time actions and run-time actions. The effect of the op/3 declaration applies only at compile-time, and furthermore only to the source where the declaration appears. Thus, in order of making the operator active at run time, you must make a call to the op/3 builtin where appropriate, for example:
------------------------------------------------------ :- use_module(library(read)). :- use_module(library(write)). :- use_module(library(operators)).
main :- op(950,xfx,'==>'), open('file.pl',read,Stream), read(Stream,A), close(Stream), write(A), nl. ------------------------------------------------------
Just for compatibility, there is a package in the standard library called 'runtime_ops' which makes op/3 declarations affect run-time (by the use of a ":- initialization" declaration). Using the package, your program would be as
------------------------------------------------------ :- use_package(runtime_ops). :- op(950,xfx,'==>').
:- use_module(library(read)). :- use_module(library(write)).
main :- open('file.pl',read,Stream), read(Stream,A), close(Stream), write(A), nl. ------------------------------------------------------
Regards,
Daniel Cabeza
Daniel Cabeza Gras says:
In Ciao, unlike in SICStus, there is a clear separation between compile-time actions and run-time actions. The effect of the op/3 declaration applies only at compile-time, and furthermore only to the source where the declaration appears. Thus, in order of making the operator active at run time, you must make a call to the op/3 builtin where appropriate, for example:
Following the Ciao philosophy regarding operators, these belong to the source file where they are used. Thus, it is not "appropriate" to do:
main :- op(950,xfx,'==>'), open('file.pl',read,Stream), read(Stream,A), ...
Instead, the op declaration should be in file.pl
Here is a simple driver that does the thing:
read_clause(Stream,Clause):- read(Stream,Clause), parse(Clause).
parse((:- op(A,B,C))):- !, op(A,B,C). parse(_Clause).
which can be used as follows (in case one does not want to read the op declarations in file.pl):
main :- open('file.pl',read,Stream), read_relevant_clause(Stream,A), close(Stream), write(A), nl.
read_relevant_clause(Stream,A):- repeat, read_clause(Stream,A), + irrelevant(A), !.
irrelevant((:-op(_,_,_))).
Francisco Bueno CLIP group - CS Dept. - FIM - UPM Campus de Montegancedo - 28660, Boadilla del Monte - Madrid Tel: +34 1 336 7448 Fax: +34 1 352 4819 Internet: bueno(a)fi.upm.es http://www.clip.dia.fi.upm.es/~bueno/