Hi folks,
I'm wondering what to make of this behavior, seen in both guile 1.8.1 and
1.8.3, discovered by my colleague L. Brown Westrick, cc:ed above:
guile> (define (apply2 f a b) (f a b))
guile> (apply2 or #t #f)
#t
guile> (apply2 and #t #f)
#t
[ #f expected ]
guile> (quit)
[because we're dealing with order here, it's useful to get a clean start.
it turns out that this doesn't reset. You will keep getting #t for
(apply2 and #t #f) and (apply2 and #f #t), though (apply2 and #f #f) will
be correct.]
guile> (define (apply2 f a b) (f a b))
guile> (apply2 and #t #f)
#f
guile> (apply2 or #t #f)
#f
[ #t expected ]
(and #t #f) and (or #t #f) are not sensitive to this -- one has to pass
them to another function and invoke them thus. I know these are not normal
procedures, in that (procedure? and) ===> #f but this still seems wrong.
I've attached a new test file boolean.test that tests this, as well as
other standard things we expect of booleans which all pass. I am in the
process of getting signed off w.r.t. copyright.
Thanks,
Grem
--
------ __@ Gregory A. Marton http://csail.mit.edu/~gremio/
--- _`\<,_ .
-- (*)/ (*) The perfect is the enemy of the good.
~~~~~~~~~~~~~~~~-~~~~~~~~_~~~_~~~~~v~~~~^^^^~~~~~--~~~~~~~~~~~~~~~++~~~~~~~
;;;; symbols.test --- test suite for Guile's symbols -*- scheme -*-
;;;;
;;;; Copyright (C) 2001, 2006 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING. If not, write to
;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;;;; Boston, MA 02110-1301 USA
;;;
;;; if, not
;;;
(pass-if "true" #t)
(pass-if "false" (not #f))
(pass-if "if true" (if #t #t #f))
(pass-if "if false" (if #f #f #t))
;;;
;;; and, or
;;;
(pass-if "(and)" (and))
(pass-if "and t" (and #t))
(pass-if "and f" (not (and #f)))
(pass-if "and tt" (and #t #t))
(pass-if "and tf" (not (and #t #f)))
(pass-if "and ft" (not (and #f #t)))
(pass-if "and ff" (not (and #f #f)))
(pass-if "and ttt" (and #t #t #t))
(pass-if "and ttf" (not (and #t #t #f)))
(pass-if "and tft" (not (and #t #f #t)))
(pass-if "and tff" (not (and #t #f #f)))
(pass-if "and ftt" (not (and #f #t #t)))
(pass-if "and ftf" (not (and #f #t #f)))
(pass-if "and fft" (not (and #f #f #t)))
(pass-if "and fff" (not (and #f #f #f)))
(pass-if "and ()" (and-map identity '()))
(pass-if "and (t)" (and-map identity '(#t)))
(pass-if "and (tt)" (and-map identity '(#t #t)))
(pass-if "and (ttt)" (and-map identity '(#t #t #t)))
(pass-if "and (ttf)" (not (and-map identity '(#t #t #f))))
(pass-if "and (fff)" (and-map not '(#f #f #f)))
(pass-if "and (123)" (equal? 3 (and 1 2 3)))
(pass-if "3=and(123)" (equal? 3 (and-map identity '(1 2 3))))
(pass-if "5=and(123)+2" (equal? 5 (and-map (lambda (x) (+ 2 x)) '(1 2 3))))
(pass-if "(or)" (not (or)))
(pass-if "or t" (or #t))
(pass-if "or f" (not (or #f)))
(pass-if "or tt" (or #t #t))
(pass-if "or tf" (or #t #f))
(pass-if "or ft" (or #f #t))
(pass-if "or ff" (not (or #f #f)))
(pass-if "or ttt" (or #t #t #t))
(pass-if "or ttf" (or #t #t #f))
(pass-if "or tft" (or #t #f #t))
(pass-if "or tff" (or #t #f #f))
(pass-if "or ftt" (or #f #t #t))
(pass-if "or ftf" (or #f #t #f))
(pass-if "or fft" (or #f #f #t))
(pass-if "or fff" (not (or #f #f #f)))
(pass-if "or ()" (not (or-map identity '())))
(pass-if "or (t)" (or-map identity '(#t)))
(pass-if "or (ft)" (or-map identity '(#f #t)))
(pass-if "or (fft)" (or-map identity '(#f #f #t)))
(pass-if "or (fff)" (not (or-map identity '(#f #f #f))))
(pass-if "or (ff3)" (equal? 3 (or #f #f 3)))
(pass-if "3=or(ff3)" (equal? 3 (or-map identity '(#f #f 3))))
(pass-if "or not(ttf)" (or-map not '(#t #t #f)))
(pass-if "-1=or(123)-2" (equal? -1 (or-map (lambda (x) (- x 2)) '(1 2 3))))
;;;
;;; and and or as arguments
;;;
(let ((apply2 (lambda (f a b) (f a b))))
(pass-if "apply and(tf)=f" (not (apply2 and #t #f)))
(pass-if "apply or(tf)=t" (apply2 or #t #f))
(pass-if "apply and(tf)=t" (apply2 and #f #t)))