Hi, I have an example from Bratko, Exercise 3.13. The problem is to make operators of 'was', 'of', 'the' in such a way as to make:
diana was the secretary of the department.
correct prolog and then to be able to write things like:
?- Who was the secretary of the department. and get: Who = diana etc.
This set of definitions doesn't work in ciao, but works in gprolog: %% file: diana.pl :- op(200, fy, the). :- op(250, xfy, of). :- op(300, yfx, was).
diana was the secretary of the department. %% end diana.pl
betenoir ~/logic> ciao Welcome to the Ciao Prolog Development System!
** WARNING **: your shell initialization scripts have not been properly modified for locating the Ciao on-line documentation. Please refer to the instructions in the file /usr/local/ciao/lib/ciao/NewUser.
Ciao-Prolog 1.8 #2: Sat Feb 8 22:26:15 MST 2003 ?- [diana]. Note: [diana] is obsolete, use ensure_loaded(diana) instead
yes ?- Who was the secretary of the department. {SYNTAX ERROR: (lns 6-6) operator expected after expression Who ** here ** was the secretary of the department . }
no ?- -- end ciao
--gprolog session: betenoir ~/logic> gprolog GNU Prolog 1.2.16 By Daniel Diaz Copyright (C) 1999-2002 Daniel Diaz | ?- [diana]. compiling /home/jd/logic/diana.pl for byte code... /home/jd/logic/diana.pl compiled, 5 lines read - 589 bytes written, 9 ms
yes | ?- Who was the secretary of the department.
Who = diana
yes | ?- -- end gprolog
I saw an email by Daniel Cabeza Gras on Aug-13-02 but I don't think that's relevant. Am I doing something wrong?
(I did :- use_module(library(operators)). also but it made no difference)
Thanks for any info,
Jeff Donner
============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
Dear Jeff,
it is not broken! :-)
In order to be truly modular, operators in Ciao are local to the modules in which they are defined (note that this is also what the ISO standard says!!). This applies also to the top level, which behaves just as if it were another module (that is why you load files into it using use_module).
The bottom line is that you have to 'activate' the operators in the top level. You can do this in the following ways:
- You can do it by hand, entering them into the top level:
Ciao-Prolog 1.9 #59: Mon Feb 17 03:09:53 CET 2003 ?- op(200, fy, the).
yes ?-
- Even better, put all the operators definitions in a file, called for example 'dianaops.pl' and *include* it both in the top level and in the program module (e.g., diana). I.e., dianaops.pl is :
%% file: dianaops.pl :- op(200, fy, the). :- op(250, xfy, of). :- op(300, yfx, was).
%% end dianaops.pl
and the program would be:
%% file: diana.pl :- include(dianaops).
diana was the secretary of the department. %% end diana.pl
and then in the top level, do:
?- ensure_loaded(diana).
yes ?- include(dianaops). {Including /tmp/dianaops.pl }
yes ?- diana was the secretary of the department.
yes
These decisions in Ciao are part of what allows having all those nice packages (function syntax, constraints, named arguments, assertions, etc., etc.) and being able to use one package (say, functional syntax) in one module and a different package (say, constraints) in another module without interaction or seeing any effect in the top level. Note that you really do not want the operators defined in some module or user file deep within an application to show up in the top level. Among other things if you used the same operator for two purposes in different modules of the program (which is very useful sometimes) they would clash in the top level.
MH
I have no ciao system in reach of my hands, so I can't test it right now, but I'm pretty sure that in ciao you can't use the operators defined in a different file. I have encountered it while doing some work with ciao and the solution I used was to simply declare all operators (which was actually only one) in every module. I'm actually quite curious if there is any smarter way to do it.
Quoting Jeff Donner <jdonner(a)cs.nmsu.edu>:
?- Who was the secretary of the department. {SYNTAX ERROR: (lns 6-6) operator expected after expression
^^^^^^^^^^^^^^^^^^ you get the error because ciao doesn't see the operators declared in a file, although any predicate declared in that file would see those operators.
Who ** here ** was the secretary of the department . }
no ?-
I have no ciao system in reach of my hands, so I can't test it right now, but I'm pretty sure that in ciao you can't use the operators defined in a different file. I have encountered it while doing some work with ciao and the solution I used was to simply declare all operators (which was actually only one) in every module. I'm actually quite curious if there is any smarter way to do it.
Dear Bartek,
this question has been answered recently (http://clip.dia.fi.upm.es/Mail/ciao-users/0367.html).
MCL
__________________ Myspacebargotstuck ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
I have encountered it while doing some work with ciao and the solution I used was to simply declare all operators (which was actually only one) in every module. I'm actually quite curious if there is any smarter way to do it.
See my previous message: one smart way to do it is to put all the operators (and all other syntactic stuff like expansions, new declarations, etc.) in a separate file and ':- include' it in all files where you need that fucntionality (and in the top level).
See the description of the concept of 'packages' in the manual (:- use_package) and, specially in the following document, which explains the philosophy behind the whole thing:
@InProceedings{ciao-modules-cl2000, author = {D.~Cabeza and M.~Hermenegildo}, title = {{A} {N}ew {M}odule {S}ystem for {P}rolog}, booktitle = {International Conference on Computational Logic, CL2000}, publisher = {Springer-Verlag}, series = {LNAI}, number = {1861}, publisher_location ={Heidelberg, Germany}, year = 2000, month = {July}, pages= {131--148}, butype = {Inproceedings}, butopics = {lang,impl,anal,spec}, projects = {EDIPIA,ECCOSIC}, paper_presentation_city ={London}, paper_presentation_country ={U.K.} }
You can get an online copy of (a TR with the same contents as this) from:
http://clip.dia.fi.upm.es/clippubsbytopic/clippubsbytopic.html
in "Publications in Programming Language Design"
MH