Quiz 2: Scheme Programming Evaluation Orders, Quizzes of Programming Languages

A quiz focused on scheme programming, specifically on understanding the difference between normal-order and applicative-order evaluation in scheme functions. The quiz includes two questions, each with different scenarios and expected outputs.

Typology: Quizzes

Pre 2010

Uploaded on 08/31/2009

koofers-user-w1m
koofers-user-w1m 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name ___________________
Quiz – 2
March 7, 2006
1) Consider the following Scheme definition:
>> (define (test x y) (if (= x 3) 1 y))
Write the output of the following call to this function
>> (test 3 (/ 5 0))
a) assuming normal-order evaluation is used (5 pts):
1
b) assuming applicative-order evaluation is used (5 pts):
Error: Division by zero!
2) Write the output of the following programs:
a) >> (let ((a 3) (b 4))
(let ((a 5) (b a))
(let ((a b) (c a))
(+ a b c)) ) )
Output (5 pts):
11 ;(3+3+5)
b) >> (let ((a 3) (b 4))
(let* ((a 5) (b a))
(let* ((a b) (c a))
(+ a b c)) ) )
Output (5 pts):
15 ;(5+5+5)

Partial preview of the text

Download Quiz 2: Scheme Programming Evaluation Orders and more Quizzes Programming Languages in PDF only on Docsity!

Name ___________________

Quiz – 2

March 7, 2006

1) Consider the following Scheme definition:

(define (test x y) (if (= x 3) 1 y))

Write the output of the following call to this function

(test 3 (/ 5 0))

a) assuming normal-order evaluation is used (5 pts):

b) assuming applicative-order evaluation is used (5 pts):

Error: Division by zero!

2) Write the output of the following programs:

a) >> (let ((a 3) (b 4)) (let ((a 5) (b a)) (let ((a b) (c a)) (+ a b c)) ) )

Output (5 pts):

b) >> (let ((a 3) (b 4)) (let* ((a 5) (b a)) (let* ((a b) (c a)) (+ a b c)) ) )

Output (5 pts):