This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Strange behavior in a catch with (and) and (or)
- To: Guile Mailing List <guile at sourceware dot cygnus dot com>
- Subject: Strange behavior in a catch with (and) and (or)
- From: Andrew Ho <andrew at tellme dot com>
- Date: Wed, 1 Mar 2000 14:44:35 -0800 (PST)
Hello,
I am trying to implement a function (nullcase fn) which returns the null
case of the function fn (e.g. the fn called with no arguments: (fn)), or
an error code if the null case errors.
Examples: (nullcase +) => 0 because (+) => 0.
(nullcase *) => 1, and (nullcase list) => '() for similar reasons.
(nullcase cons) => 'nullcase-error because (cons) is a
wrong-number-of-args error.
Here is my try at this function:
(define (nullcase fn)
(catch #t
(lambda () (fn))
(lambda (key . otherargs) 'nullcase-error) ))
It works for most cases, including all the cases I listed above as
examples. However, when I use this function on "and" and "or," weird
things happen:
guile> (nullcase +)
0
guile> (nullcase cons)
nullcase-error
guile> (nullcase and)
#t
guile> (nullcase +)
#t
And *every single call to nullcase thereafter* also returns #t.
Interestingly enough if I restart guile or redefine the nullcase function,
it behaves correctly until I call it with "and" or "or" again. Also,
(nullcase and|or) *does* return the correct null case the first time I
call it:
guile> (define (nullcase fn) ... )
guile> (nullcase +)
0
guile> (nullcase or)
#f
guile> (nullcase +)
#f
I suspect that this strange behavior is because "and" and "or" are defined
as macros. However, I'm still mightily confused about why (nullcase ...)
stops working after calling it once on either of those functions.
I'm using Guile 1.3 on Solaris x86.
Apologies if readers of this list are mainly interested in guile linkage
and not Scheme weirdness. Thanks in advance for any pointers or help!
Humbly,
Andrew
----------------------------------------------------------------------
Andrew Ho http://www.tellme.com/ andrew@tellme.com
Engineer info@tellme.com Voice 650-815-0262
Tellme Networks, Inc. Fax 650-815-0291
----------------------------------------------------------------------