File: fatfib.ss

package info (click to toggle)
chezscheme 9.5.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 58,092 kB
  • sloc: ansic: 17,515; sh: 760; makefile: 509; csh: 430; asm: 56
file content (19 lines) | stat: -rw-r--r-- 458 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
;;; fat fibonacci function

;;; this is "fat" because it uses only increments and decrements
;;; for addition and subtraction (i.e., peano arithmetic).

;;; note that fat+ is tail-recursive; this is how all looping is
;;; performed in Scheme.

(define fat+
   (lambda (x y)
      (if (zero? y)
          x
          (fat+ (1+ x) (1- y)))))

(define fatfib
   (lambda (x)
      (if (< x 2)
          1
          (fat+ (fatfib (1- x)) (fatfib (1- (1- x)))))))