Please Try These Problems on Your Own Before You Read the Solutions –

You Will Get Much More From Them That Way!

 

 

(Many of these problems are borrowed from TA Lisa)

 

Please note that solutions were derived on Dr.Scheme for Windows –

There may be slight differences between these answers and those of MacGambit.

 

(define (fish meal) ‘whatever)

(define five 5)

(define (six) 6)

 

What –exactly- is the variable ‘fish’ bound to?__A function that takes 1 arg and always returns ‘whatever.

What –exactly- is the variable ‘five’ bound to?__The number 5.

What –exactly- is the variable ‘six’ bound to?___A procedure that always returns the number 6.

 

Given the above definitions, what value and type would the following scheme expressions return? (Some may be errors.)

 

>(+ ‘1 ‘2 ‘3)

6

>(+ 1 2 3)

6

>(‘+ ‘1 ‘2 ‘3)

Error-Expected Proc

 

>(+)

0

>(*)

1

>(-)

Error-proc ‘-‘ needs at least 1 argument

>(first 2/6)

1

>(first ‘2/6)

1

>(bf 2/6)

/3

 

>(bf 00012)

2

>(bf ‘00012)

2

>(bf ‘r0012)

“0012”

 

>(se ‘(fish fish) (fish fish))

(fish fish whatever)

>(se (fish fish) (fish fish))

(whatever whatever)

>(se ‘((fish fish) (fish fish)))

Error-Arg is not a word or sentence.

 

>six

#<proc-six>

>‘six

six

>(six)

6

 

>‘(six)

(six)

>‘’(six)

‘(six)

>‘(‘six)

(‘six)

 

>five

5

>‘five

five

>(five)

Error-Expected a proc

 

>(= 1 ‘1)

#t

>(= six 6)

Error-Expected a number

>(= five 5)

#t

 

>(if (3) ‘yes ‘no)

Error-Expected a proc, got a number (3)

>(if 0 ‘yes ‘no)

yes

>(if “” ‘yes ‘no)

yes

 

>(if ‘() ‘yes no)

yes

>(let ((a 3)) a)

3

>(let ((five 6)) (+ five (six)))

12