Machine Problem 0: Getting acquainted

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:

  1. [0 pts] Get yourself a CCIS login. If you do not already have a CCIS account, follow the directions at http://www.ccs.neu.edu/welcome/ or go to 310 WVH to get a form. Be sure to follow the directions carefully!
  2. [0 pts] Subscribe to the course mailing list at https://lists.ccs.neu.edu/bin/listinfo/csg111. Be sure to include your first and last names, so we will know who is who.
  3. [1 pt] Start a Development Diary for this assignment. Take short notes in it as you work. (The point assignment for this task reflects the 10% penalty for a missing or unsatisfactory diary.)
  4. [1 pt] Start DrScheme and transcribe the following code for the PLT Scheme module mp0
    (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.

  5. [2 pt] After evaluating the 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.)

  6. [1 pt] Download drscheme-init.scm. Make sure to save it into the same directory as the mp0.scm file. Then transcribe the following code for the PLT Scheme module mp0-test
    (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.

  7. [2 pts] The hello function currently returns a string that has a meaningless word, ''modulethanks,'' in it. Spend at most ten minutes changing the hello function in the mp0 module so that the hello returns a string where the two distinct words are kept separated.

    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.

  8. [1 pt] Try running the erroneous function on various inputs. Explain the messages you get from DrScheme in your development diary.
  9. [1 pt] Spend at most five minutes changing the body of the erroneous function in the mp0 module in some manner so that it satisfies its purpose. 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.
  10. [1 pt] In any non-lisp/non-scheme language of your choice, write procedures analogous to the 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.

  11. Submit the assignment by following the submission instructions.

Your deliverables are:

  1. A PLT Scheme module "mp0.scm". The module should be written in the language (lib "eopl.ss" "eopl") and continue to provide hello and sponsor.
  2. A PLT Scheme module "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.
  3. The output from the tests, named 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.

  4. The file mp0alt.xxx (described in Task 10.)
  5. A Development Diary

Back to Machine Problems

Felix S Klock II

Last modified: 7 January 2008