f



Meaning of ':' and '{}'

Hi,
  Please, can anyone tell me what is meaning of predicates ':' and '{}'
?






----------------
yours
 
Advait

0
5/18/2006 8:46:14 AM
comp.lang.prolog 3728 articles. 0 followers. Post Follow

4 Replies
1887 Views

Similar Articles

[PageSpeed] 38

Advait wrote:
> Hi,
>   Please, can anyone tell me what is meaning of predicates ':' and '{}'
> ?

It depends on the context. : is used for module qualification of predicates.
Like
	lists:member(X,L)

The curly brackets are used in Definite Clauses Grammars: find the section on DCGs in
the manual or google for it and you will find out easily. There are uses of {} as a
functor in datastructures also.

Cheers

Bart Demoen

0
Bart
5/18/2006 10:02:19 AM
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 ?




-------------------------------
yours
Advait

0
Advait
5/20/2006 9:09:45 AM
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

0
Joachim
5/20/2006 1:08:36 PM
Thank you Joachim & Bart




----------------------
yours
Advait
  /\
 /--\

0
Advait
5/20/2006 7:52:41 PM
Reply: