home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.scheme
- Path: sparky!uunet!math.fu-berlin.de!fub!obh.in-berlin.de!heaven7.in-berlin.de!malihh!clu
- From: clu@malihh.hanse.de (Carsten Lutz)
- Subject: Re: applying or
- Message-ID: <BztwsM.3qx@malihh.hanse.de>
- Organization: malihh, Hamburg, Germany
- References: <BztJDI.1J1@malihh.hanse.de> <BztK4w.1Lt@malihh.hanse.de>
- Date: Fri, 25 Dec 1992 19:00:21 GMT
- Lines: 58
-
- In <BztK4w.1Lt@malihh.hanse.de>,I (Carsten Lutz) write:
- >In <BztJDI.1J1@malihh.hanse.de>, I write:
- >>I tried to write a little procedure which implements an "or"-function but
- >>additionally checks if it's arguments are booleans. My approach was the
- >>following:
- >>
- >> (define (b-or . oplist)
- >> (if (boollist? oplist)
- >> (apply or oplist)
- >> 'not-a-bool))
- [...]
- >And second of course I know a way to write my procedure b-or:
- >
- >(define (b-or . oplist)
- > (cond ((null? oplist) #f)
- > ((not (boolean? (car oplist))) 'not-a-bool)
- > ((eq? (car oplist) #t))
- > (else (apply b-or (cdr oplist)))))
- >
- Ok, I think I start to bother some of you by posting the third
- article about this subject, but the two b-or's above doesn't do
- the same thing ( If the first would work at all ). Imagine evaluating
-
- (b-or #t 'foobar)
-
- The first one would return 'not-a-bool, but the second one
- returns #t. So I had to rewrite the second approach:
-
- (define (b-or . oplist)
- (define (or-internal . oplist)
- (cond ((null? oplist) #f)
- ((eq? #t (car oplist)) #t)
- (else (apply or-internal (cdr oplist)))))
- (if (boollist? oplist)
- (apply or-internal oplist)
- 'not-a-bool))
-
- This is now really ugly because or-internal is in fact an or.
- If you like it all-in-one:
-
- (define (b-or . oplist)
- (define (or-internal . oplist)
- (cond ((null? (cdr oplist)) (car oplist))
- ((not (boolean? (cadr oplist))) 'not-a-bool)
- ((eq? (cadr oplist) #t) (apply or-internal
- (cons #t (cddr oplist))))
- (else (apply or-internal (cons (car oplist) (cddr oplist))))))
- (apply or-internal (cons #f oplist)))
-
- I don't like this very much either. What's the best solution ?
-
- greetings,
- Carsten
-
- P.S.: Thanx for your patience with me. ;-)
- --
- * Carsten Lutz, Rellingen, FRG / clu@malihh.hanse.de ( NeXTmail accepted ) *
- * Voice : +49 4101 512493 Fax: +49 4101 27757 Traily : +49 4101 22306 *
-