home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / scheme / 2790 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.2 KB

  1. Path: sparky!uunet!mitech!gjc
  2. From: gjc@mitech.com (George J. Carrette)
  3. Newsgroups: comp.lang.scheme
  4. Subject: Re: Summary. Interpreters are faster than I thought
  5. Message-ID: <4110@mitech.com>
  6. Date: 18 Dec 92 12:40:49 GMT
  7. References: <4094@mitech.com>
  8. Organization: Mitech Corporation, Concord MA
  9. Lines: 31
  10.  
  11. In article <4094@mitech.com>, gjc@mitech.com (George J. Carrette) writes:
  12. > So here is another version of fib that uses binary arithmetic
  13. > implemented as lists of symbols. It runs around 50 times slower
  14. > than using built-in arithmetic. 
  15.  
  16. I posted a fairly bogus version of "b-", which not only was ugly, it
  17. did not work on schemes that returned #unspecified instead of #f when
  18. falling off the end of a "if" form that had 2 instead of 3 legs.
  19.  
  20. Here is JAR's much nicer version:
  21.  
  22. ;From:    UUCP%"jar@cs.cornell.edu" 18-DEC-1992 02:32
  23. ;To:    gjc@mitech.com
  24.  
  25. ;That's a really ugly b<, try this one.
  26.  
  27. (define (b< x y)
  28.   (and (not (null? y))
  29.        (or (null? x)
  30.        (b< (cdr x) (cdr y))
  31.        (and (equal? (cdr x) (cdr y))
  32.         (eq? (car x) 'A)
  33.         (eq? (car y) 'B)))))
  34.  
  35. (define (number->b n)
  36.   (if (zero? n)
  37.       '()
  38.       (cons (if (odd? n) 'B 'A)
  39.         (number->b (quotient n 2)))))
  40.  
  41.