Re: Meaning of ':' and '{}'
- From: Joachim Schimpf <j.schimpf@xxxxxxxxxxxxxxx>
- Date: Sat, 20 May 2006 13:08:36 GMT
Advait wrote:
Hello everyone,
I had a problem with ':' in the developement of expert shell in SWI
KNOWLEDGE BASE
:- op(900,xfx,':').
:- op(880,xfx,then).
:- op(870,fx,if).
:- op(550,xfy,or).
rule : if a or b or c or d or e then problem.
%% Note the ':'
END KNOWLEDGE BASE
c:/pl/test.pl compiled 0.00 sec, 1,088 bytes
Welcome to SWI-Prolog (Multi-threaded, Version 5.4.7)
Copyright (c) 1990-2003 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?- listing.
Yes
2 ?-
This shows no rule.
If we replace ':' by any other atom it gives proper result.
Does any thing wrong with ':' ?
Please, can any one give me the solution on it to use in SWI ?
Two issues here:
1. do you really want to give your rules directly to the Prolog
compiler? The Prolog compiler will just take them as a collection
of facts (for the predicate :/2 or then/2, see below).
I find it more likely that you will need a sort or rule-compiler,
i.e. a program that reads your rules as data structures, and
transforms them into something more useful (like a decision tree).
Such a program would use e.g. read/2 to read the rules, and in
that case you will not have any problem with using the colon,
because _your_ program decides what the colon means.
2. If you give your rules to a Prolog compiler with a Quintus-style
module system (as you have done), the colon will be interpreted as
a module qualification. So your example rule is taken as a fact for
the predicate then/2 in module 'rule', because it is equivalent to
rule:then(if(or(a, or(b, or(c, or(d, e))))), problem)).
Prolog compilers that don't treat the colon specially will take it
as a fact for :/2 instead, but that probably clashes with the name
of a built-in predicate. So you should either choose a different
functor, or change the precedences such that the colon is not the
toplevel functor.
However, i really think you do not want to compile these rules as
facts at all.
-- Joachim
.
- Follow-Ups:
- Re: Meaning of ':' and '{}'
- From: Advait
- Re: Meaning of ':' and '{}'
- References:
- Meaning of ':' and '{}'
- From: Advait
- Re: Meaning of ':' and '{}'
- From: Bart Demoen
- Re: Meaning of ':' and '{}'
- From: Advait
- Meaning of ':' and '{}'
- Prev by Date: Re: Meaning of ':' and '{}'
- Next by Date: Re: Meaning of ':' and '{}'
- Previous by thread: Re: Meaning of ':' and '{}'
- Next by thread: Re: Meaning of ':' and '{}'
- Index(es):