Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpreter, if statement and let

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

like image 794
sara_123 Avatar asked May 04 '26 04:05

sara_123


1 Answers

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.

like image 54
GoZoner Avatar answered May 05 '26 18:05

GoZoner