CS257 Notes: Jan 25 1999

(taken by Will Schultz, edited into a semblance of readability by BAP)

Programming tips for the day

  1. Scheme is not case sensitive. However, characters are usually done in lower case.

  2. Parenthesis are not optional. An opening parenthesis is used to open a function call and a closing parenthesis is used to close a function call. An extra opening parenthesis means you have an extra function call, and a missing opening parenthesis means you are missing a function call.

  3. Do not start variable names with numbers.

  4. Style: Use a lot of small functions rather than one or two large functions. In C/C++ the use of small functions is considered fragmentation in your code. Scheme does not have the overhead associated with functions, so small functions are good.

Announcement concerning turning in homework

  1. Do not send a hard copy.

  2. Do not e-mail professor with large attachments.

  3. Use the "turn in script". Remove all characters ">" and comment out all non-code from the files you wish to submit. In your directory type the following:
    ~cslab/bin/cs257-handin filename.scm
    
    this will submit your file.

  4. There is a test script that will tell you (via email) if your program worked. This test is not exhaustive, but will help in finding errors. If an error is found, you can correct the error and resubmit your code. You can re-submit as many times as you like. Your last submission will be the one graded. To grade your code your TA may use (load "myfile.scm") to pull your code into a running Scheme. You should make sure your file loads into a fresh scheme without error.

Today's Lecture

Today's lecture is more of a formal overview of Scheme than last lecture. The overview will be done in BNF, a method used in the 1970s. The syntax is self explanatory [and the note taker too lazy to explain it.]
<scheme-program> := <top-level-form>...

<top-level-form> := <expression> | <definition>

<expression> := <constant> | <funcall> | <variable> | <if>

<constant> := <number> | ... (explained later in the course)

<number> := <integer> | <float> | <complex>

<integer> := <digit> <digit>...
             | '+' <digit> <digit>...
             | '-' <digit> <digit>...

<digit> := '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' 

<complex> := <float> '+' <float> 'i'

<funcall> := '(' <function> <expression> ... ')'

<function> := <variable>

<variable> := <alpha> <alpha-digit-or-odd>...

<definition> := '(define' <variable> <expression> ')'
                | '(' 'define' <variable> <lambda-expr> ')'
                | '(' 'load' '"' <filename> '"' ')'

<lambda-expr> := '(' 'lambda' '(' <variable> ...')' <expression> ')'

<if> := '(' 'if' <expression> <expression> <expression> ')'

An example of an if function:

(define sq-or-cube
  (lambda (n)
    (+ (if (< n 0)
           (* n n n)
	   (* n n)))))
an example of a function definition:
;;; Pythagorean theorem
(define pyth
  (lambda (x y)
    (sqrt (+ (* x x)
             (* y y)))))