3 Intermediate Student

► |  | How to Design Programs Languages

1 | Beginning Student
2 | Beginning Student with List Abbreviations
3 | Intermediate Student
4 | Intermediate Student with Lambda
5 | Advanced Student
| Index

▼ | 3 | Intermediate Student

3.1 | define
3.2 | define-struct
3.3 | local
3.4 | letrec, let, and let*
3.5 | Function Calls
3.6 | time
3.7 | Identifiers
3.8 | Primitive Operations
3.9 | Unchanged Forms

top← prev up next →

### 3`` Intermediate Student

program |  | = |  | def-or-expr ...
def-or-expr |  | = |  | definition
|  | | |  | expr
|  | | |  | test-case
|  | | |  | library-require
definition |  | = |  | ( define (id id id ...) expr)
|  | | |  | ( define id expr)
|  | | |  | ( define id ( lambda (id id ...) expr))
|  | | |  | ( define-struct id (id ...))
expr |  | = |  | ( local [definition ...] expr)
|  | | |  | ( letrec ([id expr-for-let] ...) expr)
|  | | |  | ( let ([id expr-for-let] ...) expr)
|  | | |  | ( let* ([id expr-for-let] ...) expr)
|  | | |  | (id expr expr ...) ; function call
|  | | |  | (prim-op expr ...) ; primitive operation call
|  | | |  | ( cond [expr expr] ... [expr expr])
|  | | |  | ( cond [expr expr] ... [ else expr])
|  | | |  | ( if expr expr expr)
|  | | |  | ( and expr expr expr ...)
|  | | |  | ( or expr expr expr ...)
|  | | |  | ( time expr)
|  | | |  | empty
|  | | |  | id ; identifier
|  | | |  | prim-op ; primitive operation
|  | | |  | ’quoted ; quoted value
|  | | |  | `quasiquoted ; quasiquote
|  | | |  | number
|  | | |  | true
|  | | |  | false
|  | | |  | string
|  | | |  | character
expr-for-let |  | = |  | ( lambda (id id ...) expr)
|  | | |  | expr
quoted |  | = |  | id
|  | | |  | number
|  | | |  | string
|  | | |  | character
|  | | |  | (quoted ...)
|  | | |  | ’quoted
|  | | |  | `quoted
|  | | |  | ,quoted
|  | | |  | ,@quoted
quasiquoted |  | = |  | id
|  | | |  | number
|  | | |  | string
|  | | |  | character
|  | | |  | (quasiquoted ...)
|  | | |  | ’quasiquoted
|  | | |  | `quasiquoted
|  | | |  | ,expr
|  | | |  | ,@expr
test-case |  | = |  | ( check-expect expr expr)
|  | | |  | ( check-within expr expr expr)
|  | | |  | ( check-member-of expr expr ...)
|  | | |  | ( check-range expr expr expr)
|  | | |  | ( check-error expr expr)
library-require |  | = |  | ( require string)
|  | | |  | ( require (lib string string ...))
|  | | |  | ( require (planet string package))
package |  | = |  | ( string string number number)

An id is a sequence of characters not including a space or one of the following:
" , ' ` ( ) [ ] { } | ; #
A number is a number such as 123, 3/2, or 5.5.
A string is enclosed by a pair of ". Unlike symbols, strings may be split into characters and manipulated by a variety of primitive functions. For example, "abcdef", "This is a string", and "This is a string with \" inside" are all strings.
A character begins with #\ and has the name of the character. For example, #\a, #\b, and #\space are characters.

A prim-op is one of:
Numbers: Integers, Rationals, Reals, Complex, Exacts, Inexacts
< : (real real real ... -> boolean)
<= : (real real real ... -> boolean)
= : (number number number ... -> boolean)
> : (real real real ... -> boolean)
>= : (real real ... -> boolean)
abs : (real -> real)
acos : (number -> number)
add1 : (number -> number)
angle : (number -> real)
asin : (number -> number)
atan : (number -> number)
ceiling : (real -> integer)
complex? : (any -> boolean)
conjugate : (number -> number)
cos : (number -> number)
cosh : (number -> number)
current-seconds : (-> integer)
denominator : (rat -> integer)
e : real
even? : (integer -> boolean)
exact->inexact : (number -> number)
exact? : (number -> boolean)
exp : (number -> number)
expt : (number number -> number)
floor : (real -> integer)
gcd : (integer integer ... -> integer)
imag-part : (number -> real)
inexact->exact : (number -> number)
inexact? : (number -> boolean)
integer->char : (integer -> char)
integer-sqrt : (number -> integer)
integer? : (any -> boolean)
lcm : (integer integer ... -> integer)
log : (number -> number)
magnitude : (number -> real)
make-polar : (real real -> number)
make-rectangular : (real real -> number)
max : (real real ... -> real)
min : (real real ... -> real)
modulo : (integer integer -> integer)
negative? : (number -> boolean)
number->string : (number -> string)
number? : (any -> boolean)
numerator : (rat -> integer)
odd? : (integer -> boolean)
pi : real
positive? : (number -> boolean)
quotient : (integer integer -> integer)
random : (integer -> integer)
rational? : (any -> boolean)
real-part : (number -> real)
real? : (any -> boolean)
remainder : (integer integer -> integer)
round : (real -> integer)
sgn : (real -> (union 1 1.0 0 0.0 -1 -1.0))
sin : (number -> number)
sinh : (number -> number)
sqr : (number -> number)
sqrt : (number -> number)
sub1 : (number -> number)
tan : (number -> number)
zero? : (number -> boolean)
Booleans
boolean=? : (boolean boolean -> boolean)
boolean? : (any -> boolean)
false? : (any -> boolean)
not : (boolean -> boolean)
Symbols
symbol->string : (symbol -> string)
symbol=? : (symbol symbol -> boolean)
symbol? : (any -> boolean)
Lists
append : ((listof any) ... -> (listof any))

assq :

(X
(listof (cons X Y))
->
(union false (cons X Y)))

caaar :

((cons
(cons (cons W (listof Z)) (listof Y))
(listof X))
->
W)

caadr :

((cons
(cons (cons W (listof Z)) (listof Y))
(listof X))
->
(listof Z))

caar : ((cons (cons Z (listof Y)) (listof X)) -> Z)

cadar :

((cons (cons W (cons Z (listof Y))) (listof X))
->
Z)

cadddr : ((listof Y) -> Y)
caddr : ((cons W (cons Z (cons Y (listof X)))) -> Y)
cadr : ((cons Z (cons Y (listof X))) -> Y)
car : ((cons Y (listof X)) -> Y)

cdaar :

((cons
(cons (cons W (listof Z)) (listof Y))
(listof X))
->
(listof Z))

cdadr :

((cons W (cons (cons Z (listof Y)) (listof X)))
->
(listof Y))

cdar :

((cons (cons Z (listof Y)) (listof X))
->
(listof Y))

cddar :

((cons (cons W (cons Z (listof Y))) (listof X))
->
(listof Y))

cdddr :

((cons W (cons Z (cons Y (listof X))))
->
(listof X))

cddr : ((cons Z (cons Y (listof X))) -> (listof X))
cdr : ((cons Y (listof X)) -> (listof X))
cons : (X (listof X) -> (listof X))
cons? : (any -> boolean)
eighth : ((listof Y) -> Y)
empty? : (any -> boolean)
fifth : ((listof Y) -> Y)
first : ((cons Y (listof X)) -> Y)
fourth : ((listof Y) -> Y)
length : ((listof any) -> number)
list : (any ... -> (listof any))
list* : (any ... (listof any) -> (listof any))
list-ref : ((listof X) natural-number -> X)
make-list : (natural-number any -> (listof any))
member : (any (listof any) -> boolean)
member? : (any (listof any) -> boolean)
memq : (any (listof any) -> (union false list))
memv : (any (listof any) -> (union false list))
null : empty
null? : (any -> boolean)
pair? : (any -> boolean)
remove : (any (listof any) -> (listof any))
rest : ((cons Y (listof X)) -> (listof X))
reverse : ((listof any) -> list)
second : ((cons Z (cons Y (listof X))) -> Y)
seventh : ((listof Y) -> Y)
sixth : ((listof Y) -> Y)
third : ((cons W (cons Z (cons Y (listof X)))) -> Y)
Posns
make-posn : (number number -> posn)
posn : signature
posn-x : (posn -> number)
posn-y : (posn -> number)
posn? : (anything -> boolean)
Characters
char->integer : (char -> integer)
char-alphabetic? : (char -> boolean)
char-ci<=? : (char char char ... -> boolean)
char-ci<? : (char char char ... -> boolean)
char-ci=? : (char char char ... -> boolean)
char-ci>=? : (char char char ... -> boolean)
char-ci>? : (char char char ... -> boolean)
char-downcase : (char -> char)
char-lower-case? : (char -> boolean)
char-numeric? : (char -> boolean)
char-upcase : (char -> char)
char-upper-case? : (char -> boolean)
char-whitespace? : (char -> boolean)
char<=? : (char char char ... -> boolean)
char<? : (char char char ... -> boolean)
char=? : (char char char ... -> boolean)
char>=? : (char char char ... -> boolean)
char>? : (char char char ... -> boolean)
char? : (any -> boolean)
Strings
explode : (string -> (listof string))
format : (string any ... -> string)
implode : ((listof string) -> string)
int->string : (integer -> string)
list->string : ((listof char) -> string)
make-string : (nat char -> string)
replicate : (nat string -> string)
string : (char ... -> string)
string->int : (string -> integer)
string->list : (string -> (listof char))
string->number : (string -> (union number false))
string->symbol : (string -> symbol)
string-alphabetic? : (string -> boolean)
string-append : (string ... -> string)
string-ci<=? : (string string string ... -> boolean)
string-ci<? : (string string string ... -> boolean)
string-ci=? : (string string string ... -> boolean)
string-ci>=? : (string string string ... -> boolean)
string-ci>? : (string string string ... -> boolean)
string-copy : (string -> string)
string-ith : (string nat -> string)
string-length : (string -> nat)
string-lower-case? : (string -> boolean)
string-numeric? : (string -> boolean)
string-ref : (string nat -> char)
string-upper-case? : (string -> boolean)
string-whitespace? : (string -> boolean)
string<=? : (string string string ... -> boolean)
string<? : (string string string ... -> boolean)
string=? : (string string string ... -> boolean)
string>=? : (string string string ... -> boolean)
string>? : (string string string ... -> boolean)
string? : (any -> boolean)
substring : (string nat nat -> string)
Images
image=? : (image image -> boolean)
image? : (any -> boolean)
Misc
=~ : (real real non-negative-real -> boolean)
eof : eof
eof-object? : (any -> boolean)
eq? : (any any -> boolean)
equal? : (any any -> boolean)
equal~? : (any any non-negative-real -> boolean)
eqv? : (any any -> boolean)
error : (any ... -> void)
exit : (-> void)
identity : (any -> any)
struct? : (any -> boolean)
Numbers (relaxed conditions)
* : (number ... -> number)
+ : (number ... -> number)
- : (number ... -> number)
/ : (number ... -> number)
Higher-Order Functions
andmap : ((X -> boolean) (listof X) -> boolean)

apply :

((X-1 ... X-N -> Y)
X-1
...
X-i
(list X-i+1 ... X-N)
->
Y)

argmax : ((X -> real) (listof X) -> X)
argmin : ((X -> real) (listof X) -> X)
build-list : (nat (nat -> X) -> (listof X))
build-string : (nat (nat -> char) -> string)

compose :

((Y-1 -> Z)
...
(Y-N -> Y-N-1)
(X-1 ... X-N -> Y-N)
->
(X-1 ... X-N -> Z))

filter : ((X -> boolean) (listof X) -> (listof X))
foldl : ((X Y -> Y) Y (listof X) -> Y)
foldr : ((X Y -> Y) Y (listof X) -> Y)
for-each : ((any ... -> any) (listof any) ... -> void)
map : ((X ... -> Z) (listof X) ... -> (listof Z))

memf :

((X -> boolean)
(listof X)
->
(union false (listof X)))

ormap : ((X -> boolean) (listof X) -> boolean)
procedure? : (any -> boolean)
quicksort : ((listof X) (X X -> boolean) -> (listof X))
sort : ((listof X) (X X -> boolean) -> (listof X))

top← prev up next →