🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #2470

what is wrong here?

#2470
From: 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*
Technical Details
Message-ID: <dt4.726861498@olive>
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!howland.reston.ans.net!spool.mu.edu!agate!stanford.edu!eos!data.nas.nasa.gov!mustang.mst6.lanl.gov!ucsbcsl!olive!dt4

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!europa.asd.contel.com!howland.reston.ans.net!spool.mu.edu!agate!stanford.edu!eos!data.nas.nasa.gov!mustang.mst6.lanl.gov!ucsbcsl!olive!dt4
From: dt4@olive.ucsb.edu (David E. Goggin)
Newsgroups: comp.lang.prolog
Subject: what is wrong here?
Summary: big problem
Keywords: wrong here
Message-ID: <dt4.726861498@olive>
Date: 12 Jan 93 17:58:18 GMT
Sender: root@ucsbcsl.ucsb.edu
Distribution: comp.lang
Lines: 24