The Scheme Programming Language

3/29/00


Click here to start


Table of Contents

The Scheme Programming Language

Scheme philosophy

Scheme

Locally available versions

C vs. Scheme expressions

Prefix vs. infix

Nested expressions 1

Nested expressions 2

Nested expressions 3

Nested expressions 4

Nested expressions 5

Evaluating arguments

Types

More types

What’s in a symbol?

Some “literals” evaluate to themselves

Symbols evaluate by variable lookup

define special form

Lists evaluate by procedure application*

Special forms

List evaluation

Creating a symbol’s value

Suppressing evaluation

quote special form

Quoting

Forcing evaluation with eval

The Lambda Calculus

Creating procedures with the lambda special form

A moment for syntax

Naming a procedure

Shorthand for procedure definition

Procedures vs. variables

Conditionals: if special form

C vs. Scheme

C vs. Scheme

eq? procedure tests for identity equality

Recursion

Linear recursive process

Lists are made of cons cells

cons cells and the cons procedure

List syntax shorthand

car, cdr, and friends

Nested lists

Do not try this at home

our-list-ref procedure

our-list-ref trace Linear iterative process

Contrast the inductive steps

Tail-recursion

our-list-ref tail recursion

Re-binding is NOT assignment

Thinking recursively

Recursion is about being a smart-aleck!

Recursion templates

Augmenting recursion examples

More augumenting recursion

Reducing functions

Tail recursive version of factorial

Tail recursive factorial trace

Conditional augumentation

Insertion sort

Nested procedure defines

Factoring out common sub-expressions

let special form

Scope is visibility

let bindings happen in parallel

Bad let bindings

let* special form

More about conditionals: cond special form

cond example

Short-circuiting and, or special forms

Boolean values & and, or

Procedures are first-class values

map, a higher-order function

Filter procedure

Typechecking predicates

Procedure factories

Building procedures

Dr. Scheme Graphics

lambdas and closures

lambdas and their environments

Free variables and Lexical Scoping

Dynamic Scoping

Lexical vs. Dynamic Scope

Lexical scope and variable hiding

When the arguments don’t fit

A more direct approach: the apply procedure

Procedure arity

Rest arguments

Controlling evaluation inside of lists

quasiquote and unquote

Forcing and suppressing evaluation are fundamental

Comparisons

eq?, eqv?, equal?

More eq?, eqv?, equal?

Objects/values in the Scheme Heap

Do not use eq? for numbers

Making new lists

Sharing of list structure

append must duplicate the list

List surgery

set-cdr! and set-car!

Assignment

set! procedure

Other side-effects

Sequencing and the begin special form

Side effects and Scwm

for-each procedure

Commenting example

Commenting style

Memory management

Scheme memory model

A view of garbage

Mark and sweep garbage collection

Reference counting

Reference counting never reclaims cycles

Mark and sweep vs. Reference counting

Author: Greg J. Badros & Alan Borning