home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mitsch75.zip / scheme-7_5_17-src.zip / scheme-7.5.17 / src / runtime / boole.scm < prev    next >
Text File  |  1999-01-02  |  2KB  |  61 lines

  1. #| -*-Scheme-*-
  2.  
  3. $Id: boole.scm,v 14.3 1999/01/02 06:11:34 cph Exp $
  4.  
  5. Copyright (c) 1988, 1999 Massachusetts Institute of Technology
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or (at
  10. your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful, but
  13. WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. |#
  21.  
  22. ;;;; Boolean Operations
  23. ;;; package: ()
  24.  
  25. (declare (usual-integrations))
  26.  
  27. (define-primitives not (false? not))
  28.  
  29. (define false #F)
  30. (define true #T)
  31.  
  32. (define (boolean? object)
  33.   (or (eq? object #F)
  34.       (eq? object #T)))
  35.  
  36. (define (boolean=? x y)
  37.   (if x y (not y)))
  38.  
  39. (define (boolean/or . arguments)
  40.   (let loop ((arguments arguments))
  41.     (cond ((null? arguments) false)
  42.       ((car arguments) true)
  43.       (else (loop (cdr arguments))))))
  44.  
  45. (define (boolean/and . arguments)
  46.   (let loop ((arguments arguments))
  47.     (cond ((null? arguments) true)
  48.       ((car arguments) (loop (cdr arguments)))
  49.       (else false))))
  50.  
  51. (define (there-exists? items predicate)
  52.   (let loop ((items items))
  53.     (and (not (null? items))
  54.      (or (predicate (car items))
  55.          (loop (cdr items))))))
  56.  
  57. (define (for-all? items predicate)
  58.   (let loop ((items items))
  59.     (or (null? items)
  60.     (and (predicate (car items))
  61.          (loop (cdr items))))))