Code Examples

This page (which you can read on the web at $PUB/code-examples.shtml) gives access to code examples in the course library and in the lecture notes directory.

You can use the table of contents (on the web) to jump directly to the kind of example you are looking for.

If you click on a Scheme file name and your browser tries to download a plugin (e.g., for a Lotus Screen Cam Movie), then you need to change your browser's rules for associating file suffixes with viewers. One way to do this on Windows (95/98) is to go into the Windows Explorer, and click on "View" then "Folder Options", then click on the "File Types" tab, and then enter a new file type for .scm files.


Contents

  1. Little Schemer, Chapter 2
  2. Little Schemer, Chapter 3
  3. Little Schemer, Chapter 4
  4. Scheme Background
  5. EOPL 2e Chapter 1
  6. EOPL 2e Chapter 2
  7. EOPL 2e Chapter 3
  8. EOPL 2e Chapter 4
  9. EOPL 2e Chapter 5
  10. EOPL 2e Chapter 6

The Little Schemer, Chapter 2

$PUB/lib/copy.scm, a prototype for these kinds of procedures, although it doesn't seem to do much.

$PUB/lib/length.scm

$PUB/lib/add1-to-each.scm

$PUB/lib/make-all-positive.scm

$PUB/lib/mapcdr.scm

$PUB/lib/map.scm

The Little Schemer, Chapter 3

$PUB/lib/delete-even.scm

The Little Schemer, Chapter 4

$PUB/lib/nat-leq.scm

$PUB/lib/nth-element.scm

$PUB/lib/unary-notation.scm

Scheme Background

Data Types

Write Scheme code to:

$PUB/lectures/basics/yodaize.scm

$PUB/lib/whos-on-first.scm

$PUB/lib/lambda*.scm, for example $PUB/lib/lambda-1-exp.scm

Understand:

$PUB/lib/dot-notation.scm

In $PUB/lib/ most files have type annotations (try the Unix command: grep deftype *.scm)

Expressions

Write Scheme code using expressions, statements, and definitions.

$PUB/lib/nth-element.scm, among many other examples in $PUB/lib.

Understand:

Procedures

$PUB/lib/matrix-ops.scm

$PUB/lib/sym-exp.scm (parse-s-list)

$PUB/lib/remove-sym-exp-with-map.scm (remove-s-list)

$PUB/lib/grav-force.scm

$PUB/lib/test-homework.scm (cs342:test-maker, cs324:eval-print-maker, cs342:regression-test-maker-maker, ...)

$PUB/lib/type-check-unify.scm (tc:list-unify-maker)

$PUB/lib/type-check-infer.scm (tc:check-application-maker, tc:infer-elements-type-lub-maker, ...)

$PUB/lib/vector-generator.scm (see $PUB/lib/vector-generator.tst and vector-map.scm for how it's used)

$PUB/lib/sum.scm

$PUB/lib/product.scm

$PUB/lib/atomic-tree.scm (tree)

$PUB/lib/set-ops.scm (set-of, set-union*)

Syntactic Abstraction

$PUB/lib/lambda-if-let-exp-examples.scm (sugar, which does the opposite of the "let" desugaring)

$PUB/lib/nat-leq.scm

$PUB/homework/set-ops.scm (set-member?, set-subset?, set-equal?)

$PUB/lib/all.scm

$PUB/lib/some.scm

$PUB/lib/type-check-unify.scm (tc:occurs-check?, ...)

$PUB/lib/whos-on-first.scm

$PUB/lib/type-check-infer.scm

EOPL Chapter 1

Inductive Specifications and Grammars (1.1)

$PUB/lib/lambda*.scm, for example $PUB/lib/lambda-1-exp.scm

The document defining our type notation, which uses BNF.

$PUB/lib/type-check-output-type-expr.scm

Deriving Recursive Programs from Grammars (1.2)

$PUB/lib/sum.scm (sum-of-list)

$PUB/lib/product.scm (product-of-list)

$PUB/lib/type-check-utils.scm (tc:last-item, tc:some, tc:member?, tc:filter, tc:find-duplicates, ...)

$PUB/lib/set-ops.scm

$PUB/lib/type-predicates.scm (list-of)

$PUB/lectures/count-sym-exp.scm

$PUB/lib/subst.scm

$PUB/lib/num-of.scm

$PUB/lib/remove-sym-exp.scm

try these using $PUB/lib/sym-exp-cooked.scm also, instead of $PUB/lib/sym-exp.scm

$PUB/lib/lambda*-examples.scm, for example $PUB/lib/lambda-1+quote-examples.scm

$PUB/lib/type-check-output-type-expr.scm

$PUB/lib/type-check-type-expr.scm

$PUB/lib/type-check-type-translate.scm (tc:type-vars, tc:output-type-vars, tc:nest-args, tc:type-unnest-args, tc:substq-all-output)

Tail Recursion (1.2.3)

Examples of full recursion are found in the section above on deriving recursive programs from grammars. Compare the code for the fully recursive $PUB/lib/product.scm with the tail recursive code in $PUB/lib/product-tail-recursive.scm. Note the pending computations surrounding the recursive calls in the fully-recursive version.

$PUB/lib/product-tail-recursive.scm

$PUB/lib/list-index.scm

$PUB/lectures/induction-recursion/vector-product.scm

$PUB/lib/type-check-scheme-parser.scm (tc:get-file-suffix and tc:last-dot-in-file-pos)

$PUB/lib/type-check-utils.scm (tc:last-item)

$PUB/lib/vector-map-bang.scm

$PUB/lib/whos-on-first.scm (get-context, try-strong-cues, try-weak-cues)

$PUB/lib/type-check-utils.scm (tc:find-duplicates)

$PUB/lib/vector-generator.scm

$PUB/lib/type-predicates.scm (vector-of)

Scope and Binding of Variables (1.3)

$PUB/lib/lambda-1-exp-examples.scm (free-vars, free?, bound-vars, bound?)

$PUB/lib/combinator-tools.scm (occurs-free-in?)

$PUB/lib/combinators.scm

$PUB/lib/y.scm

see also $PUB/lib/combinator-tools.scm

EOPL Chapter 2

Specifying Data via Interfaces (2.1)

Abstraction for Inductive Data Types (2.2)

$PUB/lib/lambda*-examples.scm, for example $PUB/lib/lambda-1+number-exp-examples.scm

$PUB/lib/lnm-if-exp-examples.scm

$PUB/lib/arith-expr-examples.scm

$PUB/lib/type-check-type-expr.scm (tc:occurs-in-type-expr?)

$PUB/lib/type-check-external-type-expr.scm

$PUB/lib/type-check-type-translate.scm (tc:type-vars, tc:external-type-vars, tc:nest-args, tc:type-unnest-args, tc:substq-all-external)

$PUB/lib/combinator-tools.scm (toCombinators, interpret, toLambda, occurs-free-in?)

Data Abstraction (2.3)

$PUB/lib/stack.scm

$PUB/lib/seq-as-proc.scm

$PUB/lib/seq-as-ast.scm

Transformation of Procedural to Abstract Syntax Tree Representations (2.3.2-2.3.3)

$PUB/lib/seq-as-proc.scm transformed to $PUB/lib/seq-as-ast.scm

$PUB/lib/environment-as-proc.scm transformed to $PUB/lib/environment-as-ast.scm

$PUB/lib/phone-book-as-proc.scm transformed to $PUB/lib/phone-book-as-ast.scm and optimized to a ribcage representation in $PUB/lib/phone-book-as-ribcage.scm

$PUB/lib/road-map-as-proc.scm transformed to $PUB/lib/road-map-as-ast.scm

Last modified Sunday, March 28, 2004.

This web page is for the Spring 2004 offering of Com S 342 at Iowa State University. The details of this course are subject to change as experience dictates. You will be informed of any changes. Thanks to Curtis Clifton for help with these web pages. Please direct any comments or questions to Gary T. Leavens at leavens@cs-DOT-iastate-DOT-edu (after replacing -DOT- with `.').