🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.prolog
1 messages
1 total messages Started by David E. Goggin Tue, 12 Jan 1993 17:58
what is wrong here?
#2470
Author: David E. Goggin
Date: Tue, 12 Jan 1993 17:58
23 lines
1105 bytes
Hi folks.

I am trying to teach myself prolog, and I am having a problem.  I
programmed a fibonacci number finder.

  fib(1,1).            /* fib(S,N) where N is the Sth fibonacci # */
  fib(2,1).
  fib(S,N) :- S>2,
              A is S-1,
              B is S-2,
              fib(A,C),
              fib(B,D),
              N is C+D.

but all I get when I try to ask fib(5,X) is error: free variable in
expression.  But there is stuff like this in C&M's book!  How do I
get the 5th fib. number?

second question: how do I get the second element of a list?
[A|B|C]?  where B is second element?  or maybe [A|[B|C]]?

thanks in advance!
*dt*
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads