unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* sending and and or as an argument links their behavior
@ 2008-01-26  0:07 Gregory Marton
  2008-01-26 13:16 ` Neil Jerram
  0 siblings, 1 reply; 3+ messages in thread
From: Gregory Marton @ 2008-01-26  0:07 UTC (permalink / raw)
  To: bug-guile; +Cc: Linda Brown Westrick

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1359 bytes --]

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~~~~^^^^~~~~~--~~~~~~~~~~~~~~~++~~~~~~~

[-- Attachment #2: Type: TEXT/PLAIN, Size: 3458 bytes --]

;;;; 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)))


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sending and and or as an argument links their behavior
  2008-01-26  0:07 sending and and or as an argument links their behavior Gregory Marton
@ 2008-01-26 13:16 ` Neil Jerram
  2008-01-26 18:33   ` Gregory Marton
  0 siblings, 1 reply; 3+ messages in thread
From: Neil Jerram @ 2008-01-26 13:16 UTC (permalink / raw)
  To: Gregory Marton; +Cc: bug-guile, Linda Brown Westrick

Gregory Marton <gremio@csail.mit.edu> writes:

> 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 ]

`or' and `and' are macros, and it doesn't work to pass them as
procedure arguments.

I forget for the moment what R5RS says; I suspect the above is not
allowed, and so perhaps Guile should detect it and report an error.

The detailed reason for this is Guile's memoization - but that's not
really the main point.

Regards,
        Neil





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: sending and and or as an argument links their behavior
  2008-01-26 13:16 ` Neil Jerram
@ 2008-01-26 18:33   ` Gregory Marton
  0 siblings, 0 replies; 3+ messages in thread
From: Gregory Marton @ 2008-01-26 18:33 UTC (permalink / raw)
  To: Neil Jerram; +Cc: bug-guile, Linda Brown Westrick

> `or' and `and' are macros, and it doesn't work to pass them as
> procedure arguments.
>
> I forget for the moment what R5RS says; I suspect the above is not
> allowed, and so perhaps Guile should detect it and report an error.
>
> The detailed reason for this is Guile's memoization - but that's not
> really the main point.

If guile will continue to behave this way, then yes, reporting an error 
would save some pain.  As a user, I would much prefer to view it as a bug, 
because I don't want to have to care whether something like (and...) is 
implemented as a macro or as a procedure.  This may be hopelessly naive.


I tried to find the part of R5RS that defines this behavior.  Section 4.3 
talks about keywords binding to macro transformers in a very different way 
than it talks about variables binding to values in 4.1.1, as if it is 
licensing a separate namespace, reminiscent of Lisp's function and data 
namespaces (except that a single identifier may only mean one at a time). 
Section 7.1.3 makes explicit that procedure calls are different from macro 
uses, which are (<keyword> <datum>*), not (<operator> <operand>*), 
consistent with the above.  This looks to the untrained eye like a wart.

In contrast, the guile docs on Procedures and Macros talk about macros as 
first class things: "when a symbol defined to this value appears as the 
first symbol in an expression", which makes me think I can define a symbol 
to that value, pass it around, and expect it to work as the first symbol in 
an s-expression.  I see that "pass it around" is never made explicit, but 
it would certainly be consistent, and partly The Way Things Are.  I hope 
that a memoization bug won't kill this bit of beauty.

I apologise if I badly misunderstood something.  I am a novice here, and 
speak only as a relatively recent user, curious to learn more.

Thanks,
Grem

-- 
------ __@   Gregory A. Marton                http://csail.mit.edu/~gremio/
--- _`\<,_                                                                .
-- (*)/ (*)                Oh Lord, give me patience... NOW!
~~~~~~~~~~~~~~~~-~~~~~~~~_~~~_~~~~~v~~~~^^^^~~~~~--~~~~~~~~~~~~~~~++~~~~~~~





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-01-26 18:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-26  0:07 sending and and or as an argument links their behavior Gregory Marton
2008-01-26 13:16 ` Neil Jerram
2008-01-26 18:33   ` Gregory Marton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).