1
votes

thinking following expression:

(cond (p1 (some_complex_expression1))
      (p2 (some_complex_expression2))
      (p3 (some_complex_expression3))
      ...
      (else (some_complex_expressionN)))

are those (some_complex_expressionX)s evaluated on demand? (i.e. '(some_complex_expressionX)' is only evaluated when the predicate before itself, pX is true) or, do they follow applicative order(they are somehow evaluated as much as possible before trying predicates)

if that is implementation-dependent, how about those following implementations?

mit-scheme
guile
racket
that scheme for sicp
r5rs
2

2 Answers

4
votes

The test must return a true value before the associated expressions are evaluated. This is guaranteed by the Scheme standards; see section 4.2.1 of R5RS, for example.

1
votes

For the gory details on Racket, see the Reference Manual. For this question, you're asking about the semantics of cond; the documentation there steps through the details on what is or isn't evaluated under what conditions.