# Prolog

Page 1 of 1

## 4 Replies - 1633 Views - Last Post: 04 April 2009 - 06:23 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=97055&amp;s=978d9178ef20c8c36e878e843417770c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 chetah

Reputation: 2
• Posts: 112
• Joined: 17-November 07

# Prolog

Posted 03 April 2009 - 04:25 AM

New to prolog, trying to understand how a list works in prolog.

I am trying to write a clause (what is a clause in this context?) sumList(List, sum) which returns the sum of the numbers in a list. an example would help a lot in seeing what is a clause?
Is This A Good Question/Topic? 0

## Replies To: Prolog

### #2 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: Prolog

Posted 04 April 2009 - 02:39 PM

you mean a predicate??, a predicate is basically a boolean function, it only returns true or false..

### #3 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: Prolog

Posted 04 April 2009 - 02:45 PM

this is a simple problem, i'd show you the solution but you have to show some effort first..i'll give you a hint though, a list consists of a head and a tail right??, so the sum of the elements in the list will be the head + the elements in the tail..actually that was the solution, if you can figure out the base case and translate this to syntax then problem is solved

This post has been edited by mostyfriedman: 04 April 2009 - 02:46 PM

### #4 chetah

Reputation: 2
• Posts: 112
• Joined: 17-November 07

## Re: Prolog

Posted 04 April 2009 - 02:54 PM

sumlist([],0).
sumlist([H|T],N) :- sumlist(T,N1), N is N1+H.
how close am I?

### #5 mostyfriedman

• The Algorithmi

Reputation: 729
• Posts: 4,473
• Joined: 24-October 08

## Re: Prolog

Posted 04 April 2009 - 06:23 PM

not close, you are there ...you got the solution