7.9

Simply Scheme Support Definitions

Danny Yoo <dyoo@cs.wpi.edu>

1Introduction

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).

2Quick 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")

3Table of Scheme Primitives by Category

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

4Alphabetical Listing of Scheme Primitives

 (require simply-scheme) package: simply-scheme

 syntax
multiply numbers

 syntax

 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
Return the absolute value of the argument.

 syntax
Apply a combining function to all the elements.

 syntax
Return a string spaced to a given width.

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

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

 syntax
Return a list containing the elements of the argument lists.

 syntax
Apply a function to the arguments in a list.

 syntax
Return association list entry matching key.

 syntax
Does the first argument come alphabetically before the second?

 syntax
(Special form) Carry out a sequence of instructions.

 syntax
Abbreviation for butfirst.

 syntax
Abbreviation for butlast.

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

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

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

 syntaxc...r
Combinations of car and cdr.

 syntax
Return the first element of a list.

 syntax
Return all but the first element of a list.

 syntax
Round a number up to the nearest integer.

 syntax
Return a list of the children of a tree node.

 syntax
Close all open input and output ports.

 syntax
Close an input port.

 syntax
Close an output port.

 syntax
(Special form) Choose among several alternatives.

 syntax
Prepend an element to a list.

 syntax
Return the cosine of a number (from trigonometry).

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

 syntax
Return the datum of a tree node.

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

 syntax
Print the argument without starting a new line.

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

 syntax
Is the argument an end-of-file object?

 syntax
Are the two arguments the same thing?

 syntax

 syntax
Is the argument an even integer?

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

 syntax
Raise the first argument to the power of the second.

 syntax
Select a subset of a list.

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

 syntax
Round a number down to the nearest integer.

 syntax
Perform a computation for each element of a list.

 syntax
(Special form) Choose between two alternatives.

 syntax
Is the argument an integer?

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

 syntax
Select a subset of a word or sentence.

 syntax
(special form) Create a new procedure.

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

 syntax
Return the number of elements in a list.

 syntax
(Special form) Give temporary names to values.

 syntax
Return a list containing the arguments.

 syntax
Return a vector with the same elements as the list.

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

 syntax
Is the argument a list?

 syntax
Read a program file into Scheme.

 syntax
Return the logarithm of a number.

 syntax
Create a new node of a tree.

 syntax
Create a new vector of the given length.

 syntax
Apply a function to each element of a list.

 syntax
Return the largest of the arguments.

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

 syntax
Is the first argument an element of the second?

 syntax
Return the smallest of the arguments.

 syntax
Go to a new line of printing.

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

 syntax
Is the argument the empty list?

 syntax
Is the argument a number?

 syntax
Is the argument an odd number?

 syntax
Open a file for reading, return a port.

 syntax
Open a file for writing, return a port.

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

 syntax
Is the argument a procedure?

 syntax
(Special form) Return the argument, unevaluated.

 syntax
Divide number, but round down to integer

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

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

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

 syntax
Apply a combining function to all elements of list.

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

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

 syntax
Round a number to the nearest integer.

 syntax
Abbreviation for sentence.

 syntax
Join the arguments together into a big sentence.

 syntax
Is the argument a sentence?

 syntax
Print the argument and start a new line.

 syntax
Show the argument sentence without surrounding parentheses.

 syntax
Return the sine of a number (from trigonometry).

 syntax
Return the square root of a number.

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

 syntax
Report on all further invocations of a procedure.

 syntax
Undo the effects of trace.

 syntax
Create a vector with the arguments as elements.

 syntax
Return a list with the same elements as the vector.

 syntax
Return the number of elements in a vector.

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

 syntax
Replace an element in a vector.

 syntax
Is the argument a vector?

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

 syntax
Joins words into one big word.

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

 syntax
Print the argument in machine-readable form.

5Deviations from plain racket

5.1Strings 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:

 syntax
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.

6Differences 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.

7Thanks!

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.