Practicum 1
Due: Thursday, 31 January.
Objectives:
- Introduction to Scheme and DR Scheme.
- Expressions and variables.
Reference: The Scheme Programming Language,
R. Kent Dybvig, Addison-Wesley, 2003.
Requirements:
- Write solutions to the following problems in the definitions window
of DrScheme. Save them in a
file with a .scm extension and name the file with your last name.
Drag the file into
the user/faculty/barrj/CS 321/TurnIn/Practicum 1 folder.
- You must turn in a hard copy of your functions.
- You may not use any imperative features like set!
or loops in any of your solutions.
- You must work individually!
- Write the Scheme expressions that denote the same calculations
as the following arithmetic expressions. Verify your answers
by conducting the appropriate experiment on the computer. Turn
in written Scheme code or a screen dump
- (4 X 7) - (13 + 5)
- (3 X (4 + (-5 - -3)))
- (2.5 / (5 X (1 / 10)))
- 5 X ((537 X (98.3 + (375 - (2.5 X 153)))) + 255)
- Using the symbols one and two and the procedure
cons, we can construct the list (one two) by typing
(cons 'one (cons 'two '())). Using the symbols one, two,
three, and four and the procedure cons, construct
the following lists without using quoted lists (you may use quoted
symbols and the empty list). Turn in a written copy of your Scheme
code.
- (one two three four)
- (one (two three four))
- (one (two three) four)
- ((one two) (three four))
- (((one)))
- We can extract the symbol a from the list
(b (a c) d) using the car and cdr by
going through the following steps:
(cdr '(b (a c) d)) gives ((a c) d)
(car (cdr '(b (a c) d))) gives (a c)
(car (car (cdr '(b (a c) d)))) gives a
For each of the following lists, write the expression using car
and cdr that extracts the symbol a:
- (b c a d)
- ((b a) (c d))
- ((d c) (a) b)
- (((a)))