home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / prolog / 2354 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  1.0 KB

  1. Path: 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
  2. From: dt4@olive.ucsb.edu (David E. Goggin)
  3. Newsgroups: comp.lang.prolog
  4. Subject: what is wrong here?
  5. Summary: big problem
  6. Keywords: wrong here
  7. Message-ID: <dt4.726861498@olive>
  8. Date: 12 Jan 93 17:58:18 GMT
  9. Sender: root@ucsbcsl.ucsb.edu
  10. Distribution: comp.lang
  11. Lines: 24
  12.  
  13. Hi folks.
  14.  
  15. I am trying to teach myself prolog, and I am having a problem.  I
  16. programmed a fibonacci number finder.
  17.  
  18.   fib(1,1).            /* fib(S,N) where N is the Sth fibonacci # */
  19.   fib(2,1).
  20.   fib(S,N) :- S>2,
  21.               A is S-1,
  22.               B is S-2,
  23.               fib(A,C),
  24.               fib(B,D),
  25.               N is C+D.
  26.  
  27. but all I get when I try to ask fib(5,X) is error: free variable in
  28. expression.  But there is stuff like this in C&M's book!  How do I
  29. get the 5th fib. number?
  30.  
  31. second question: how do I get the second element of a list?
  32. [A|B|C]?  where B is second element?  or maybe [A|[B|C]]?
  33.  
  34. thanks in advance!
  35. *dt*
  36.  
  37.