Scheme Programming Homework: Recursive Functions for Counting and Collecting Symbols - Pro, Assignments of Programming Languages

A homework assignment for a cs3723 course at the university of texas at san antonio. Students are required to write recursive functions in scheme for counting symbols in an arbitrary value and collecting symbols into a new list. Test cases for each function.

Typology: Assignments

Pre 2010

Uploaded on 07/30/2009

koofers-user-jfd
koofers-user-jfd 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 1 (20pts)
due electronically by the end of Jan 28, 2009
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 online at
www.cs.utsa.edu/~cs3723.
1. (10pts) Define a recursive function count-symbols which takes an arbitrary value yand returns
how many symbols are contained within y. Use the following test cases for your function.
> (count-symbols 7)
0
> (count-symbols ’y)
1
> (count-symbols ’(x 3 y))
2
> (count-symbols ’((x 3) (y 2) (3 z)))
3
2. (10pts) Define a recursive function count2symbols which takes an arbitrary value yand returns
how many times two symbols are next to each other within y. Use the following test cases for
your function.
> (count2symbols 7)
0
> (count2symbols ’y)
0
> (count2symbols ’(x 3 y))
0
> (count2symbols ’(3 x y))
1
> (count2symbols ’((x y z) (3 z 4)))
2
3. Extra-credit(10pts) Define a recursive function collect-symbols which takes an arbitrary value
yand returns a new list that contains only the symbols in y. Use the following test cases for
your function.
> (collect-symbols 7)
empty
> (collect-symbols ’y)
’y
> (collect-symbols ’(x 3 y))
(list ’x ’y)
> (collect-symbols ’((x 3) (y 2) (3 z)))
(list (list ’x) (list ’y) (list ’z))
1

Partial preview of the text

Download Scheme Programming Homework: Recursive Functions for Counting and Collecting Symbols - Pro and more Assignments Programming Languages in PDF only on Docsity!

Homework 1 (20pts)

due electronically by the end of Jan 28, 2009

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 online at

www.cs.utsa.edu/~cs3723.

  1. (10pts) Define a recursive function count-symbols which takes an arbitrary value y and returns how many symbols are contained within y. Use the following test cases for your function.

(count-symbols 7) 0 (count-symbols ’y) 1 (count-symbols ’(x 3 y)) 2 (count-symbols ’((x 3) (y 2) (3 z))) 3

  1. (10pts) Define a recursive function count 2 symbols which takes an arbitrary value y and returns how many times two symbols are next to each other within y. Use the following test cases for your function.

(count2symbols 7) 0 (count2symbols ’y) 0 (count2symbols ’(x 3 y)) 0 (count2symbols ’(3 x y)) 1 (count2symbols ’((x y z) (3 z 4))) 2

  1. Extra-credit(10pts) Define a recursive function collect-symbols which takes an arbitrary value y and returns a new list that contains only the symbols in y. Use the following test cases for your function.

(collect-symbols 7) empty (collect-symbols ’y) ’y (collect-symbols ’(x 3 y)) (list ’x ’y) (collect-symbols ’((x 3) (y 2) (3 z))) (list (list ’x) (list ’y) (list ’z))