in reply to Re^3: An infix fix
in thread An infix fix

As AND and OR, I think they should behave as the ops: AND returns the first false value, or the last true value if no false values are encountered; OR returns the first true value, or the last false value if no true values are encountered.
I'd be curious to learn how the languages that have multi-arg AND and OR resolve this question. Of the languages I'm familiar with only Scheme fits this description, and, at least in the Scheme implementations I have on my machine (PLT Scheme/mzscheme and MIT Scheme), (and) is true and (or) is false; e.g. (for MIT Scheme):
1 ]=> (and) ;Value: #t 1 ]=> (and 3) ;Value: 3 1 ]=> (and 0) ;Value: 0 1 ]=> (or) ;Value: () 1 ]=> (or 3) ;Value: 3 1 ]=> (or 0) ;Value: 0
The way I understand these generalized versions of these functions is that AND is false if any of its arguments is false, true otherwise; OR is true if any of its arguments is true, false otherwise. In this formulation, the case of no arguments is not problematic.

the lowliest monk

Replies are listed 'Best First'.
Re^5: An infix fix
by Roy Johnson (Monsignor) on Mar 23, 2005 at 00:13 UTC
    Scheme appears to be behaving as I described, returning operand values. It also has special behavior for no-argument cases. Note that (and 3) is not the same as (and 3 #t), so recursing down to the empty list will not emulate its behavior.

    I don't object to defining the zero-arguments case; I just object to using it as the basis for nonzero-argument cases. It is a special case:

    sub AND { @_ > 1 ? shift && AND(@_) : @_ ? shift : '#t'; }

    Caution: Contents may have been coded under pressure.