home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.scheme
- Path: sparky!uunet!cs.utexas.edu!torn!newshub.ccs.yorku.ca!newshub.ccs.yorku.ca!oz
- From: oz@ursa.sis.yorku.ca (Ozan Yigit)
- Subject: fibs [Re: Are interpreters now as fast...]
- In-Reply-To: schwartz@roke.cs.psu.edu's message of 15 Dec 92 01: 10:15 GMT
- Message-ID: <OZ.92Dec15134929@ursa.sis.yorku.ca>
- Sender: news@newshub.ccs.yorku.ca (USENET News System)
- Organization: York U. Student Information Systems Project
- References: <4051@mitech.com> <BzA0Mo.II@cs.psu.edu>
- Date: Tue, 15 Dec 1992 18:49:29 GMT
- Lines: 105
-
- Scott Schwartz writes [in response to the usual simple fib]:
-
- Of course, nothing that runs for that short a time will be a sensible
- yardstick.
-
- Here are the FIB routines I had been using in PSI tests. Just something
- with more meat for those who are tired of the potatoe :-) version.
-
- enjoy... oz
- ---
- C++ was invented because Vogon poetry | electric: oz@sis.yorku.ca
- wasn't destructive enough. -anonymous | ph:[416] 736 2100 x 33976
-
- --- cut here ---
- ;;; fib
- ;;; shamelessly snarfed from
- ;;; R. Kent Dybvig
- ;;; Three Implementation Models for Scheme
- ;;; Department of Computer Science Technical Report #87-011
- ;;; University of North Carolina at Chapel Hill
- ;;; April 1987
-
- ;;; fib with peano arithmetic (using numbers)
-
- (define addr
- (rec addr
- (lambda (x y)
- (if (zero? y)
- x
- (addr (1+ x) (1- y))))))
-
- (define fibr
- (rec fibr
- (lambda (x)
- (if (zero? x)
- 0
- (if (zero? (1- x))
- 1
- (addr (fibr (1- x))
- (fibr (1- (1- x)))))))))
-
- ;;; fib with peano arithmetic (using numbers) in CPS
-
- (define addk
- (rec addk
- (lambda (x y k)
- (if (zero? y)
- (k x)
- (addk (1+ x) (1- y) k)))))
-
- (define fibk
- (rec fibk
- (lambda (x k)
- (if (zero? x)
- (k 0)
- (if (zero? (1- x))
- (k 1)
- (fibk (1- x)
- (lambda (a)
- (fibk (1- (1- x))
- (lambda (b)
- (addk a b k))))))))))
-
- ;;; fib with peano arithmetic (using numbers) with set!
-
- (define add!
- (lambda (x y)
- ((rec add!
- (lambda ()
- (if (zero? y)
- x
- (begin (set! x (1+ x))
- (set! y (1- y))
- (add!))))))))
-
- (define fib!
- (rec fib!
- (lambda (x)
- (if (zero? x)
- 0
- (if (zero? (1- x))
- 1
- (add! (fib! (1- x))
- (fib! (1- (1- x)))))))))
-
- ;;; fib with peano arithmetic (using numbers) with call/cc
-
- (define addc
- (rec addc
- (lambda (x y k)
- (if (zero? y)
- (k x)
- (addc (1+ x) (1- y) k)))))
-
- (define fibc
- (rec fibc
- (lambda (x c)
- (if (zero? x)
- (c 0)
- (if (zero? (1- x))
- (c 1)
- (addc (call/cc (lambda (c) (fibc (1- x) c)))
- (call/cc (lambda (c) (fibc (1- (1- x)) c)))
- c))))))
-
-