Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.acsu.buffalo.edu!news.uoregon.edu!arclight.uoregon.edu!mr.net!www.nntp.primenet.com!nntp.primenet.com!news.mathworks.com!rill.news.pipex.net!pipex!uknet!usenet1.news.uk.psi.net!uknet!uknet!newsfeed.ed.ac.uk!dcs.ed.ac.uk!cnews
From: ato@dcs.ed.ac.uk (Alan Ogilvie)
Subject: Re: a simple question!!!
X-Nntp-Posting-Host: ramna.dcs.ed.ac.uk
Message-ID: <E5Cur3.I5r.0.staffin.dcs.ed.ac.uk@dcs.ed.ac.uk>
Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
Organization: Department of Computer Science, Edinburgh University
X-Newsreader: knews 0.9.6
References: <32FA040A.7DE6@mailbox.swipnet.se>
Date: Sun, 9 Feb 1997 21:37:49 GMT
Lines: 80

In article <32FA040A.7DE6@mailbox.swipnet.se>,
	Jesper Malmn <jesper.malmen@mailbox.swipnet.se> writes:
>could someone please explain these rules in natural language?
>I'd appreciate it much.
>sum([],0).
>sum([H|T],Result):-
>        sum(T,Rest),
>        Result is H + Rest.

The | (or bar) is the 'cons' operator (judging by my last posting to
this newsgroup, I'll probably get jumped on - 'cons' is not the proper
name for it in Prolog, but comes from the language ML), I shall
explain what this does:

Okay, you've got a list, say [1,2,3,4] and you put this into prolog as
a goal like this...

	| ?- [H|T] = [1,2,3,4].

	H = 1,
	T = [2,3,4] ? 

Notice, what you get back is the H variable instantiated to 1 (the
Head of the list - and element) and the T variable instantiated to
[2,3,4] (the Tail of the list - a list)

Is this any help?

>not(A):- \+(A).

The \+ bit infront of the (A) term means NOT, ie if you are thinking
in logic terms then the \+ operator provides the NOT operator (what's
true is false and what's false is true).

So this rule will succeed if A is false... if true it will fail.

Try entering:

	| ?- \+true.
	no

	| ?- \+false.
	yes

Simple. So when you asked seperate questions...

>what is \?
>and what is + ?

You'll actually see that \+ is a single operator.

The rule:
>count(L,N):- length(L,N).

Is a peculiar one indeed. I cannot really see the point of this rule, you
see the length predicate is usually built into the prolog system (I know it
is in Sicstus Prolog), it returns the length of the list L in N. So try...

	| ?- length([a,b,c,d],N).
	N = 4 ? 

So putting the count predicate sitting on top of this, seems a little
unneccessary since all it does is call length. I suppose this is quite
useful if you have already called it something else, but looks very
much like a hack.

Hope this helped.

-- 
--
-------------------------------------------------------------------------
:Alan Ogilvie : A.T.Ogilvie@ed.ac.uk                          (Personal):
:WWW Page/s   : http://www.tardis.ed.ac.uk/~alan/             (Personal):
-------------------------------------------------------------------------
"Some men see things as they are and say 'why?' I dream things that never
were and say 'why not?'"                                [Robert F.Kenedy]
=========================================================================



