문제

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"?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top