Code Examples
$Date: 2001/11/05 20:26:43 $
This page (which you can read on the web at http://www.cs.iastate.edu/~leavens/ComS342-EOPL2e/docs/code-examples.html)
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
-
Scheme Background
-
EOPL 2e Chapter 1
-
EOPL 2e Chapter 2
-
EOPL 2e Chapter 3
-
EOPL 2e Chapter 4
-
EOPL 2e Chapter 5
-
EOPL 2e Chapter 6
Scheme Background
Write Scheme code to:
-
Construct and lists and improper lists
-
Use of quote, cons, and list primitives (and when to use each)
-
Extract parts of lists and improper lists
$PUB/lib/whos-on-first.scm
$PUB/lib/lambda*.scm, for example $PUB/lib/lambda-1-exp.scm
Understand:
In $PUB/lib/
most
files have type annotations (try the Unix command: grep deftype *.scm)
Write Scheme code using expressions, statements, and definitions.
-
Make decisions using if expressions
-
Make declarations using define
Understand:
-
Differences between expressions, statements, and declarations.
-
How to desugar expressions in Scheme (let, and, or, cond, case)
$PUB/lib/lambda-if-let-exp-examples.scm
(sugar, which does the opposite of the "let" desugaring)
-
Be able to use let, letrec, and, or, cond, case in Scheme programs.
There are lots of examples of this. You can grep for the appropriate
keyword to find examples in the library files. The following are
some simple examples.
EOPL Chapter 1
-
How grammar relates to the outline of a recursive procedure (1.2.1)
-
Write recursive programs over flat lists (1.2.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)
-
Write recursive programs over symbol-expression and lists of symbol-expressions
(s-lists, pp. 19-22)
$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
-
Write recursive programs over grammars
$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)
Understand the difference between full recursion and tail recursion.
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.
Write tail-recursive procedures:
$PUB/lib/product-tail-recursive.scm
$PUB/lib/list-index.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)
EOPL Chapter 2
Specifying Data via Interfaces (2.1)
-
Use of define-datatype to declare
variant record types
-
Abstract syntax that corresponds to a concrete syntax.
-
Use of cases in recursive programming, especially over some abstract syntax.
$PUB/lib/lambda*-examples.scm,
for example $PUB/lib/lambda-1+number-exp-examples.scm
$PUB/lib/lnm-if-exp-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?)
-
Representation types and defrep
$PUB/lib/stack.scm
$PUB/lib/seq-as-proc.scm
$PUB/lib/seq-as-ast.scm
$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
Gary T. Leavens