home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / scheme / 2830 < prev    next >
Encoding:
Text File  |  1992-12-25  |  2.3 KB  |  69 lines

  1. Newsgroups: comp.lang.scheme
  2. Path: sparky!uunet!math.fu-berlin.de!fub!obh.in-berlin.de!heaven7.in-berlin.de!malihh!clu
  3. From: clu@malihh.hanse.de (Carsten Lutz)
  4. Subject: Re: applying or
  5. Message-ID: <BztwsM.3qx@malihh.hanse.de>
  6. Organization: malihh, Hamburg, Germany
  7. References: <BztJDI.1J1@malihh.hanse.de> <BztK4w.1Lt@malihh.hanse.de>
  8. Date: Fri, 25 Dec 1992 19:00:21 GMT
  9. Lines: 58
  10.  
  11. In <BztK4w.1Lt@malihh.hanse.de>,I (Carsten Lutz) write:
  12. >In <BztJDI.1J1@malihh.hanse.de>, I write:
  13. >>I tried to write a little procedure which implements an "or"-function but
  14. >>additionally checks if it's arguments are booleans. My approach was the
  15. >>following:
  16. >>
  17. >> (define (b-or . oplist)
  18. >>   (if (boollist? oplist)
  19. >>       (apply or oplist)
  20. >>       'not-a-bool))
  21. [...]
  22. >And second of course I know a way to write my procedure b-or:
  23. >
  24. >(define (b-or . oplist)
  25. >  (cond ((null? oplist) #f)
  26. >        ((not (boolean? (car oplist))) 'not-a-bool)
  27. >        ((eq? (car oplist) #t))
  28. >        (else (apply b-or (cdr oplist)))))
  29. >
  30. Ok, I think I start to bother some of you by posting the third
  31. article about this subject, but the two b-or's above doesn't do
  32. the same thing ( If the first would work at all ). Imagine evaluating
  33.  
  34. (b-or #t 'foobar)
  35.  
  36. The first one would return 'not-a-bool, but the second one
  37. returns #t. So I had to rewrite the second approach:
  38.  
  39.   (define (b-or . oplist)
  40.     (define (or-internal . oplist)
  41.       (cond ((null? oplist) #f)
  42.             ((eq? #t (car oplist)) #t)
  43.             (else (apply or-internal (cdr oplist)))))
  44.     (if (boollist? oplist)
  45.         (apply or-internal oplist)
  46.         'not-a-bool))
  47.   
  48. This is now really ugly because or-internal is in fact an or. 
  49. If you like it all-in-one:
  50.  
  51. (define (b-or . oplist)
  52.   (define (or-internal . oplist)
  53.     (cond ((null? (cdr oplist)) (car oplist))
  54.           ((not (boolean? (cadr oplist))) 'not-a-bool)
  55.           ((eq? (cadr oplist) #t) (apply or-internal
  56.                                          (cons #t (cddr oplist))))
  57.           (else (apply or-internal (cons (car oplist) (cddr oplist))))))
  58.   (apply or-internal (cons #f oplist)))
  59.  
  60. I don't like this very much either. What's the best solution ?
  61.  
  62. greetings,
  63.         Carsten
  64.  
  65. P.S.: Thanx for your patience with me. ;-)
  66. -- 
  67. * Carsten Lutz, Rellingen, FRG / clu@malihh.hanse.de ( NeXTmail accepted )  *
  68. *   Voice : +49 4101 512493  Fax: +49 4101 27757  Traily : +49 4101 22306   *
  69.