Problem Set 2 Solved Questions - Programming Languages | CS 3723, Assignments of Programming Languages

Material Type: Assignment; Class: Programming Languages; Subject: Computer Science; University: University of Texas - San Antonio; Term: Fall 2008;

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-svm
koofers-user-svm 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 2
due Sep 22, 2008
The homework requires you to solve the following problems via scheme programming. You need
to develop your scheme programs using the DrScheme environment and submit your solution file
electronically via email to [email protected].
1. (15pts) Define a recursive function count which takes two parameters, an atomic value (a
symbol or a number) xand an arbitrary value y. The function returns the number of times
that xappears in y. Use the following test cases for your function.
> (count 3 7)
0
> (Check ’y ’y)
1
> (count ’x ’((x 3) (y 2) (3 z)))
1
> (count 3 ’((x 3) (y 2) (3 z)))
2
> (count ’z ’(x (z 5) (4 (z 4))))
2
> (count ’4 ’(x (z 4) (4 (z 4))))
3
2. (15pts) Define a recursive function Check which takes two parameters, an atomic value (a
symbol or a number) xand an arbitrary value y. The function finds the first occurrence of
xin yand returns the first component in ythat immediately contains x. If xis not in y, an
empty list is returned. Use the following test cases for your function.
> (Check 3.2 ’y)
empty
> (Check ’y ’y)
’y
> (Check ’x ’((x 3) (y 2) (3 z)))
(list ’x 3)
> (Check ’z ’(x (z 5) (4 (z 4))))
(list ’z 5)
1

Partial preview of the text

Download Problem Set 2 Solved Questions - Programming Languages | CS 3723 and more Assignments Programming Languages in PDF only on Docsity!

Homework 2

due Sep 22, 2008

The homework requires you to solve the following problems via scheme programming. You need to develop your scheme programs using the DrScheme environment and submit your solution file electronically via email to [email protected].

  1. (15pts) Define a recursive function count which takes two parameters, an atomic value (a symbol or a number) x and an arbitrary value y. The function returns the number of times that x appears in y. Use the following test cases for your function.

(count 3 7) 0 (Check ’y ’y) 1 (count ’x ’((x 3) (y 2) (3 z))) 1 (count 3 ’((x 3) (y 2) (3 z))) 2 (count ’z ’(x (z 5) (4 (z 4)))) 2 (count ’4 ’(x (z 4) (4 (z 4)))) 3

  1. (15pts) Define a recursive function Check which takes two parameters, an atomic value (a symbol or a number) x and an arbitrary value y. The function finds the first occurrence of x in y and returns the first component in y that immediately contains x. If x is not in y, an empty list is returned. Use the following test cases for your function.

(Check 3.2 ’y) empty (Check ’y ’y) ’y (Check ’x ’((x 3) (y 2) (3 z))) (list ’x 3) (Check ’z ’(x (z 5) (4 (z 4)))) (list ’z 5)