Reputation: 433
Why is it not possible to simulate "if-then-else" construct as a function in interpreter that supports function application? Is "let" function in Scheme similar to "if-then-else"?
Upvotes: 3
Views: 351
Reputation: 70235
An if
statement in Scheme looks like:
(if <predicate> <consequent> <alternate>)
and is defined such that the <consequent>
is evaluated only when the <predicate>
is not false and such that the <alternate>
is evaluated only when the <predicate>
is false. So you can see that something like
(if #t (display "okay") (shut-down-the-nsa))
would never actually shut down the NSA.
But, if if
is a function, like:
(<operator> <operand> …)
then each <operand>
is always evaluated. In the context of an if
statement, that means both the <consequent>
and <alternate>
would be evaluated - not much of an if
then.
Upvotes: 4