For Programmers: Free Programming Magazines  


Home > Archive > Prolog > January 2006 > newbie question









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 newbie question
Rob Frohwein

2006-01-10, 4:10 am

Hi ,

I want to learn prolog.
What is a good book? I am a c/c++ programmer.

In some examples I see:

Definition of numbers:

unary_num(0).
unary_num(s(X)):-unary_num(X).

But s is nowhere defined, is it some buitltin?
successor of X?



thanks
Rob
bill

2006-01-10, 4:10 am

Rob Frohwein wrote:
> Hi ,
>
> I want to learn prolog.http://kti.mff.cuni.cz/~bartak/prolog/index.html


> What is a good book? I am a c/c++ programmer.


Before I spent any money on a book, I'd check out

http://kti.mff.cuni.cz/~bartak/prolog/contents.html

if I were you.

>
> In some examples I see:
>
> Definition of numbers:
>
> unary_num(0).
> unary_num(s(X)):-unary_num(X).
>
> But s is nowhere defined; is it some built-in?
> successor of X?
>


Yes.

The given propositions can be read as a "definition" of the natural
numbers if '0' is taken to mean (denote) zero and, for any natural
number X, 's(X)' is taken to mean the successor of X.
Bart Demoen

2006-01-10, 4:10 am

bill wrote:
> Rob Frohwein wrote:
>


>
> Yes.


These were two questions, with one Yes as answer - since that
might be misleading, I'd like to comment in it. First of all

s is not s (some) built-in
^^^

s/1 is a function symbol or functor in Prolog speak, and you are
allowed to use practically any name (sometimes between quotes)
as a functor


>
> The given propositions can be read as a "definition" of the natural
> numbers if '0' is taken to mean (denote) zero and, for any natural
> number X, 's(X)' is taken to mean the successor of X.


This is a valid reading of the program, most probably the intended one, and
the one that comes to mind of anyone who knows about the integers.
One is free to have other readings.

Cheers

Bart Demoen
Sponsored Links







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

Copyright 2008 codecomments.com