Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Scheme Question The following program can be used to determine if a given interp

ID: 3785726 • Letter: S

Question

Scheme Question

The following program can be used to determine if a given interpreter is using applicative-order evaluations or normal-order evaluation:

(Assume that the evaluation rule for the special form 'if' is the same for both evaluation schemes: The predicate (condition) expression is evaluated first, and the result determines whether to evaluate the consequent (then) or the alternative (else) expression.)

What will be the behaviour of this code on an interpreter that uses applicative-order evaluation? Explain why.

What behaviour will be observed with an interpreter that uses normal-order evaluation? Explain why.

Which style of interpreter does Scheme use (assuming #lang R5RS)?

Explanation / Answer

The behaviour that Ben will observe with an interpreter that uses applicative-order evaluation is as follows firstly the case of normal-order evaluation, (test 0 (p)) is evaluated as follows:

(test 0 (p))

(if (= 0 0)

    0

    (p)

(if (= 0 0)

    0

    (p)

(if #t

    0

    (p)

0

The behavior he will observe with an interpreter that uses normal-order evaluation can be in the applicative order and (test 0 (p)) is evaluated as follows:

(test 0 (p))

(test 0 (p))

(test 0 ((p)))

(test 0 (((p))))

...

Here the interpreter keeps adding parentheses around (p) until infinity, and there will never be a result printed, because it will take forever to evaluate the expression (test 0 (p)).

R5RS is the most widely implemented standard style of interpreter in a scheme program. Scheme's interpreter reads a Scheme expression, evaluates it, prints the result, and repeats the process until there is no more to be interpreted.

PLT Scheme tools in their default modes do not conform to R5RS, mainly because PLT Scheme tools generally expect modules, and R5RS does not define a module system. Typical single-file R5RS programs can be converted to PLT Scheme programs by prefixing them with #langR5RS, but other Scheme systems do not#langR5RS. The PLT- R5RS executable more directly conforms to the R5RS standard.

It is of the form

(define(x)(x))

(define (test x,y))

)

Now we return our attention to Scheme. The "if" expression has the same meaning with the following form:

(if <condition-expression> <true-expression> <false-expression>)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote