This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Using And

3 posts · 5387 views

Lets say we have:

((and (something1)(something2)(something3)(something4)) #t)

How does it compute it, does it test if all four are true or does it in pairs like:

((something1)and(something2)=true and((something3)and(something4)=true)) Then the whole thing is true???

Thanks.

Re: Using And

From the R5RS standard, and is defined as
-- library syntax: and <test1> ...,
     The <test> expressions are evaluated from left to right, and the
     value of the first expression that evaluates to a false value (see
     section *note Booleans::) is returned.  Any remaining expressions
     are not evaluated.  If all the expressions evaluate to true
     values, the value of the last expression is returned.  If there
     are no expressions then #t is returned.

     (and (= 2 2) (> 2 1))                  ==>  #t
     (and (= 2 2) (< 2 1))                  ==>  #f
     (and 1 2 'c '(f g))                    ==>  (f g)
     (and)                                  ==>  #t

Re: Using And

dsjoka wrote:Lets say we have:

((and (something1)(something2)(something3)(something4)) #t)
Your expression appears malformed and would generate an error (unless quoted); I am guessing you want something such as:
(and (something1)(something2)(something3)(something4) #t)
dsjoka wrote:How does it compute it, does it test if all four are true or does it in pairs like:
In Scheme, 'and' is a special form (not a function). It evaluates each of its arguments one at a time, stopping when that evaluation is false (subsequent arguments will not be evaluated). If the end of all arguments is reached without any falses, the value of the last argument is returned.

(and w x y z)
is equivalent to
(if w (if x (if y z)))

Note that since 'and' is not a function, you can not use it with either 'map' or 'apply'.