CSCI 431: Functional Programming Languages

Functional Programming

Functional Programming Languages

LISP

Scheme

Interacting with Scheme

Scheme Expressions

Atoms and lists

Evaluation rules for atoms

Evaluation rules for lists

Stopping Evaluation

Predicates

Defining functions

Examples of user defined predicates

(define (positive? x)
   (>= x 0))
(define (twice? x y)
  (= x (* 2 y)))

When we call twice with these arguments:

(twice 4 2)

The body is

(= x (* 2 y))

Where x is bound to 4 and y is bound to 2. So (* 2 y) returns 4, and x is 4, and = returns t, so twice returns t.

(define (zero? x) (= x 0))

(define (plus? x) (> x 0))

(define (minus? x) (< x 0))

Conditionals

Logical Combinations

A Recursive Function

Cond

Making Lists

Getting Inside Lists

A List Related Predicates

Adding Elements to Lists

Boxes and Pointer Notation

Eq?

Equal?