Simply Scheme Support Definitions
1 Introduction
2 Quick Start
3 Table of Scheme Primitives by Category
3.1 Words and Sentences
3.2 Lists
3.3 Trees
3.4 Arithmetic
3.5 True and False
3.6 Variables
3.7 Vectors
3.8 Procedures
3.9 Higher-Order Procedures
3.10 Control
3.11 Input /   Output
3.12 Files and Ports
4 Alphabetical Listing of Scheme Primitives
*
+
-
/
<
<=
=
>
>=
abs
accumulate
align
and
appearances
append
apply
assoc
before?
begin
bf
bl
boolean?
butfirst
butlast
c...r
car
cdr
ceiling
children
close-all-ports
close-input-port
close-output-port
cond
cons
cos
count
datum
define
display
empty?
eof-object?
equal?
error
even?
every
expt
filter
first
floor
for-each
if
integer?
item
keep
lambda
last
length
let
list
list->vector
list-ref
list?
load
log
make-node
make-vector
map
max
member
member?
min
newline
not
null?
number?
odd?
open-input-file
open-output-file
or
procedure?
quote
quotient
read
read-line
read-string
reduce
remainder
repeated
round
se
sentence
sentence?
show
show-line
sin
sqrt
square
trace
untrace
vector
vector->list
vector-length
vector-ref
vector-set!
vector?
vowel?
word
word?
write
5 Deviations from plain racket
5.1 Strings are numbers
strings-are-numbers
6 Differences from the book and things to fix
7 Thanks!
7.1

Simply Scheme Support Definitions

Danny Yoo <[email protected]>

1 Introduction

This library adds a Simply Scheme teaching language into DrRacket; the language is used in the textbook:

Simply Scheme / Introducing Computer Science, Second Edition

Brian Harvey and Matthew Wright

MIT Press, 1999

http://www.cs.berkeley.edu/~bh/ss-toc2.html

The original source of these programs can be found from the FTP site at ftp://ftp.cs.berkeley.edu/pub/scheme. The definitions in this library should correspond to those in "simply.scm" version 3.13 (8/11.98).

2 Quick Start

Although we use these definitions from switching the DrRacket language level to Simply Scheme, this library can also be easily used as a #lang language.

For example, if your DrRacket language level has been set to Determine language from source, then the following example should run without any trouble:

#lang simply-scheme
(se (butlast (bf "this"))
    "world")

3 Table of Scheme Primitives by Category

(Primitives with a ’*’ are not part of standard Scheme)

3.1 Words and Sentences

3.2 Lists

3.3 Trees

3.4 Arithmetic

3.5 True and False

3.6 Variables

3.7 Vectors

3.8 Procedures

3.9 Higher-Order Procedures

3.10 Control

3.11 Input / Output

3.12 Files and Ports

4 Alphabetical Listing of Scheme Primitives

 (require simply-scheme) package: simply-scheme

syntax

*

multiply numbers

syntax

+

add numbers

syntax

-

subtract numbers

syntax

/

divide numbers

syntax

<

Is the first argument less than the second?

syntax

<=

Is the first argument less than or equal to the second?

syntax

=

Are two numbers equal? (Like equal? but works only for numbers)

syntax

>

Is the first argument greater than the second?

syntax

>=

Is the first argument greater than or equal to the second?

syntax

abs

Return the absolute value of the argument.

Apply a combining function to all the elements.

syntax

align

Return a string spaced to a given width.

syntax

and

(Special form) Are all of the arugments true values (i.e., not #f)?

Return the number of times the first argument is in the second.

syntax

append

Return a list containing the elements of the argument lists.

syntax

apply

Apply a function to the arguments in a list.

syntax

assoc

Return association list entry matching key.

syntax

before?

Does the first argument come alphabetically before the second?

syntax

begin

(Special form) Carry out a sequence of instructions.

syntax

bf

Abbreviation for butfirst.

syntax

bl

Abbreviation for butlast.

syntax

boolean?

Return true if the argument is #t or #f.

syntax

butfirst

Return all but the first letter of a word, or word of a sentence.

syntax

butlast

Return all but the last letter of a word, or word of a sentence.

syntax

c...r

Combinations of car and cdr.

syntax

car

Return the first element of a list.

syntax

cdr

Return all but the first element of a list.

syntax

ceiling

Round a number up to the nearest integer.

syntax

children

Return a list of the children of a tree node.

Close all open input and output ports.

Close an input port.

Close an output port.

syntax

cond

(Special form) Choose among several alternatives.

syntax

cons

Prepend an element to a list.

syntax

cos

Return the cosine of a number (from trigonometry).

syntax

count

Return the number of letters in a word or number of words in a sentence.

syntax

datum

Return the datum of a tree node.

syntax

define

(Special form) Create a global name (for a procedure or other value).

syntax

display

Print the argument without starting a new line.

syntax

empty?

Is the arugment empty, i.e., the empty word "" or the empty sentence ()?

Is the argument an end-of-file object?

syntax

equal?

Are the two arguments the same thing?

syntax

error

Print an error message and return to the Scheme prompt.

syntax

even?

Is the argument an even integer?

syntax

every

Apply a function to each element of a word or sentence.

syntax

expt

Raise the first argument to the power of the second.

syntax

filter

Select a subset of a list.

syntax

first

Return first letter of a word, or first word of a sentence.

syntax

floor

Round a number down to the nearest integer.

syntax

for-each

Perform a computation for each element of a list.

syntax

if

(Special form) Choose between two alternatives.

syntax

integer?

Is the argument an integer?

syntax

item

Return the nth letter of a word, or nth word of a sentence.

syntax

keep

Select a subset of a word or sentence.

syntax

lambda

(special form) Create a new procedure.

syntax

last

Return last letter of a word, or last word of a sentence.

syntax

length

Return the number of elements in a list.

syntax

let

(Special form) Give temporary names to values.

syntax

list

Return a list containing the arguments.

Return a vector with the same elements as the list.

syntax

list-ref

Select an element from a list (counting from zero).

syntax

list?

Is the argument a list?

syntax

load

Read a program file into Scheme.

syntax

log

Return the logarithm of a number.

syntax

make-node

Create a new node of a tree.

Create a new vector of the given length.

syntax

map

Apply a function to each element of a list.

syntax

max

Return the largest of the arguments.

syntax

member

Return subset of a list starting with the selected element, or #f.

syntax

member?

Is the first argument an element of the second?

syntax

min

Return the smallest of the arguments.

syntax

newline

Go to a new line of printing.

syntax

not

Return #t if the argument is #f; return #f otherwise.

syntax

null?

Is the argument the empty list?

syntax

number?

Is the argument a number?

syntax

odd?

Is the argument an odd number?

Open a file for reading, return a port.

Open a file for writing, return a port.

syntax

or

(Special form) Are any of the arguments true values (i.e., not #f)?

Is the argument a procedure?

syntax

quote

(Special form) Return the argument, unevaluated.

syntax

quotient

Divide number, but round down to integer

syntax

read

Read an expression from the keyboard (or a file).

syntax

read-line

Read a line from the keyboard (or a file), returning a sentence.

Read a line from the keyboard (or a file), returning a string.

syntax

reduce

Apply a combining function to all elements of list.

syntax

remainder

Return the remainder from dividing the first number by the second.

syntax

repeated

Return the function described by f(f(...(f(x)))).

syntax

round

Round a number to the nearest integer.

syntax

se

Abbreviation for sentence.

syntax

sentence

Join the arguments together into a big sentence.

syntax

sentence?

Is the argument a sentence?

syntax

show

Print the argument and start a new line.

syntax

show-line

Show the argument sentence without surrounding parentheses.

syntax

sin

Return the sine of a number (from trigonometry).

syntax

sqrt

Return the square root of a number.

syntax

square

Not a primitive! (define (square x) (* x x)).

syntax

trace

Report on all further invocations of a procedure.

syntax

untrace

Undo the effects of trace.

syntax

vector

Create a vector with the arguments as elements.

Return a list with the same elements as the vector.

Return the number of elements in a vector.

Return an element of a vector (counting from zero).

Replace an element in a vector.

syntax

vector?

Is the argument a vector?

syntax

vowel?

Not a primitive! (define (vowel? x) (member x ’(a e i o u)))

syntax

word

Joins words into one big word.

syntax

word?

Is the argument a word? (Note: numbers are words.)

syntax

write

Print the argument in machine-readable form.

5 Deviations from plain racket

5.1 Strings are numbers

One distinguishing feature of this language is the abstraction of numbers. Strings are also treated as numbers by the arithmetic operators:
> (+ "40" 2)

42

This can be enabled or disabled by using strings-are-numbers:

If bool is set to #t, strings will be treated as numbers, and the arithmetic operators will be overloaded to work with strings. If bool is set to #f, strings will not be treated as numbers.

6 Differences from the book and things to fix

FIXME: the other helper libraries haven’t been mapped yet. (things like functions.scm would be nice to have as a library.)

I also need to improve the documentation to use Scribble features; the current work is a rush job.

7 Thanks!

Thanks to my professors at UC Berkeley, especially Brian Harvey and Dan Garcia. Yes, CS61A was the best computer science class I’ve taken.

Thanks to Reid Oda for catching a very ugly bug involving namespaces, and Matthew Flatt for telling me how to fix it. See http://list.cs.brown.edu/pipermail/plt-scheme/2007-February/016387.html.