CSC 270 - Survey of Programming Languages: Scheme (Racket)

CSC 171 - Compound Data, Part 2: Lists

Lists

Creating Lists

Extracting Items From a List

First and Rest : Examples

Exercise

Add-up-3 template

Lists and structures

Data Definitions for Lists of Arbitrary Length

Lists of Arbitrary Size

Recursive definitions

Problem: Is there a doll on our list?

Designing Programs for Self-Referential Data Definitions

Data analysis and design

Template

Program Body

Combining Values

The Revised Design Recipe

Data Analysis & Design To formulate a group of data definitions Develop a data definition for mixed data with at least 2 alternatives, one which can't be self-referential
Contract Header & Purpose To name the program, to specify its inputs & outputs, to describe its purpose, to formulate a program header name the program, its input, outputs, and specify its purpose:
;; name : in1 in2.. -> out
;  to compute out
(define (name x1 x2 ..) ..)
Examples To characterize the input-output relationship via examples Create examples of the input-output relationship, with at least one example per alternative.
Template To formulate an outline for a group of programs Develop a cond-expression with one clause per alternative One alternative cannot refer to the definition. Have at least one example per alternative
Body To define the program Formulate a Scheme expression for each simple cond-line. Explain for all other cond-clauses what each natural recursion will compute. Formulate an answer using selectors, parameters, etc.
Test To expose mistakes ("typos" and logic) Apply the program to examples and check against the expected output.

Processing Simple Lists: Another Example

Header, Contract and Examples for Sum

Writing the program body

[Back to the Notes Index]