Programming Languages (CSC-302 98S)

[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Assignments]


Outline of Class 21: Functional Programming: The Scheme Perspective

Held: Wednesday, March 11, 1998

Administrivia


An Introduction to LISP-Like Languages

Lists in LISP-Like Languages

An Introduction to Scheme

Scheme in the MathLAN

A Few Scheme Programs

Compute the factorial of n

(define (fact n)
  (if (= n 0) 1 (* n fact (- n 1))))

Add an element to the end of a list

(define (addend x l)
  (if (null? l)
    (list x)
    (cons (car l) (addend x (cdr l)))))

Reverse a list (yes, it's built-in, but we can still define it)

(define (reverse l)
  (if (null? l)
    ()
    (addend (car l) (reverse (cdr l)))))

A Tail-recursive reverse

(define (tailrev l r)
  (if (null? l)
    r
    (tailrev (cdr l) (cons (car l) r))))
(define (reverse l)
  (tailrev l ()))

Higher-Order Functions


On to Other Issues in Functional Languages and Scheme
Back to Introduction to Functional Programming
Outlines: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
Current position in syllabus


[Instructions] [Search] [Current] [Changes] [Syllabus] [Handouts] [Outlines] [Assignments]

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Thu May 7 20:29:40 1998.

This page generated on Thu May 7 20:34:42 1998 by SiteWeaver.

Contact our webmaster at rebelsky@math.grin.edu