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.
Using And
Re: Using And
From the R5RS standard, and is defined as
Code: Select all
-- 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
Your expression appears malformed and would generate an error (unless quoted); I am guessing you want something such as:dsjoka wrote:Lets say we have:
((and (something1)(something2)(something3)(something4)) #t)
(and (something1)(something2)(something3)(something4) #t)
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.dsjoka wrote:How does it compute it, does it test if all four are true or does it in pairs like:
(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'.