University of Virginia, Department of Computer Science
CS200: Computer Science, Spring 2003

Notes: Wednesday 5 February 2003


Null/Nil Confusion

In SICP, they use nil. In MzScheme (DrScheme's language), they use null. The Revised5 Report on the Algorithmic Language Scheme mentions nil but uses the empty list (denoted by '()) instead. As the footnote on page 101 explains, the exact meaning and name for the empty list is cause for lots of dispute and confusion. We will use null in class to be consistent with MzScheme, and reserve nil for reporting soccer scores.

(define (gauss-sum n)
  (if (= n 0) 0 (+ n (gauss-sum (- n 1)))))

(define (insertl lst f stopval)
  (if (null? lst) stopval
      (f (car lst) 
	 (insertl (cdr lst) f stopval))))

(define (intsfrom n)
  (if (= n 0) null
      (cons n (intsfrom (- n 1)))))

(define (intsto n)
  (if (= n 0) null
      (append (intsto (- n 1)) (list n))))

(define (gauss-sum n)
  (insertl (intsto n) + 0))

(define (factorial n)
  (insertl (intsto n) * 1))

(define (map f lst)
  (if (null? lst) null 
      (cons (f (car lst)) 
	    (map f (cdr lst))))

(define (map f lst)
  (insertl lst (lambda (a b) (cons (f a) b)) null))

    def f ≡ isposint → iszero → g1 ; g2 o [f o dec, g3] ; error
     ::= def f ≡ isposint → (/l:(g2 o [s1, g3 o s2])) o al o [g1 o ~0, intsto] ; error
FL Rewrite Rule (/l is insertl), shown for amusement purposes only.
FL is a language John Backus (the B in BNF, and the designer of Fortran) designed.
It was designed to make manipulating functions very compact and powerful, but very few people ever used it and no one does anymore.
When I was an intern at IBM Almaden, I worked on developing rules like this to make FL programs run faster.

CS 200

CS 200: Computer Science
Department of Computer Science
University of Virginia
Using these Materials