Out: Monday, January 7, 2008 / Wednesday, January 9, 2008
Due: 5 PM Friday, January 11, 2008
Submission: Individual
The main goal of this assignment is to introduce the basic infrastructure and tools for doing homeworks in this course. By the end of this assignment, you should be able to:
This assignment is deliberately designed to be simple, so that you get experience with the course infrastructure without worrying too much about actual programming. In particular, you should not get bogged down in details regarding the Scheme language; if you are having problems making headway on the assignment, contact the course staff well before Friday.
Tasks:
(module mp0 (lib "eopl.ss" "eopl") (provide hello sponsor) ; exports for use in other modules. (define hello-msg "Hello from the MP0 module") (define sponsor-msg "thanks to the number ") ;; sponsor : Number -> String ;; usage: (sponsor n) returns message of thanks to n. (define sponsor (lambda (num) (string-append sponsor-msg (number->string num)))) ;; hello : (Any -> String) ;; usage: (hello anything) welcomes us and thanks the number zero. (define hello (lambda (ignored) (string-append hello-msg (sponsor 0)))) ;; erroneous : Number -> String ;; usage: (erroneous n) returns some welcome message, ignoring n. (define erroneous (lambda (num) ("A third Hello" " -- is it sick?"))) ;; Above are definitions for the module. ;; Below are expressions that are evaluated when the module is run. (display (hello "from MP0!")) (newline) )
In DrScheme's Language menu, use the Choose Language... command
to select the (module ...)
language.
Hit the Run button to evaluate the mp0
module definition.
Save the mp0 module definition into a file named mp0.scm.
mp0
module, do the following finger exercises in the DrScheme interactions
window.
Run the sponsor function on various inputs, such as (sponsor 111). What happens if you run (sponsor "zero")?
Spend at most five minutes attempting to construct
an expression that uses the substring function
to extract just the
string "ello"
from the value of the expression
(hello 0).
Briefly document your experiences on these exercises in your development diary. (Note that full credit on this task does not require successful completion of the substring task.)
(module mp0-test (lib "eopl.ss" "eopl") (require "mp0.scm") (require "drscheme-init.scm") (stop-after-first-error #t) ; (use #f to continue other tests after failure) (run-tests! sponsor string=? (list (list "sponsor0" 0 "thanks to the number 0") (list "sponsor1" 1 "thanks to the number 1"))) ;; string-starts-with? : String String -> Bool ;; usage: (string-starts-with? s p) returns true if and only if ;; p is a prefix of s. (define string-starts-with? (lambda (str pre) (string=? (substring str 0 (min (string-length str) (string-length pre))) pre))) (run-tests! hello string-starts-with? (list (list "hello0" 0 "Hello") (list "hello1" 'some-symbol "Hello") (list "hello2" "Any String" "Hello"))) )Save the
mp0-test
module definition into a file
named mp0-test.scm.
Then hit Run; review the output to check that
all of the tests pass.
For this assignment you are not required to understand the body
of the mp0-test
module.
However, since we will be using this test infrastructure in
future assignments, it is not a waste of effort to review its code.
Make sure that the tests in the mp0-test
module
continue to run successfully.
If you are not successful in this task, write notes in your development diary documenting what experimental changes you tried and what foiled your attempts.
hello
and sponsor
functions in the mp0
module.
Examples of such languages are
Java, Perl, Python, C, C++, Javascript, Basic, Forth; there are
many others. Demonstrate how you
would define something like the mp0
module if you had your
choice of (non-Scheme) language to work in.
Put your code into a file named
mp0alt.xxx
, where xxx is
whatever extension is appropriate for the language selected.
Also, explicitly indicate which language you selected,
either in the mp0alt.xxx
file
itself or in your development diary.
Your deliverables are:
"mp0.scm"
.
The module should be written in the language
(lib "eopl.ss" "eopl")
and continue
to provide hello
and sponsor
.
"mp0-test.scm"
.
The module should be written in the language
(lib "eopl.ss" "eopl")
, require
the modules "drscheme-init.scm"
and "mp0.scm"
,
and continue to run the tests it started with.
mp0-test-output.txt
.
One way of doing this is to take the contents of the
DrScheme interaction window and paste it into a
fixed-width text processor.
There is also a "Save Interactions as Text..." command, under
the "Save Other" submenu of DrScheme's File menu.
Whatever technique you use, make sure you double-check that the
submission is just text and that it matches the output you see
when you run the mp0-test
module.
mp0alt.xxx
(described in
Task 10.)
Last modified: 7 January 2008