For Programmers: Free Programming Magazines  


Home > Archive > Prolog > May 2006 > Meaning of ':' and '{}'









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Meaning of ':' and '{}'
Advait

2006-05-18, 4:01 am

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






----------------
yours

Advait

Bart Demoen

2006-05-18, 8:02 am

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

Advait

2006-05-20, 4:07 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

Joachim Schimpf

2006-05-20, 8:02 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

Advait

2006-05-20, 7:01 pm

Thank you Joachim & Bart




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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com