5.16 Primitive Operations
5.16.1 Numbers: Integers, Rationals, Reals, Complex, Exacts, Inexacts
< : (real real real ... -> boolean) |
Purpose: to compare real numbers for less-than
<= : (real real real ... -> boolean) |
Purpose: to compare real numbers for less-than or equality
= : (number number number ... -> boolean) |
Purpose: to compare numbers for equality
> : (real real real ... -> boolean) |
Purpose: to compare real numbers for greater-than
>= : (real real ... -> boolean) |
Purpose: to compare real numbers for greater-than or equality
Purpose: to compute the absolute value of a real number
acos : (number -> number) |
Purpose: to compute the arccosine (inverse of cos) of a number
add1 : (number -> number) |
Purpose: to compute a number one larger than a given number
Purpose: to extract the angle from a complex number
asin : (number -> number) |
Purpose: to compute the arcsine (inverse of sin) of a number
atan : (number -> number) |
Purpose: to compute the arctan (inverse of tan) of a number
Purpose: to determine the closest integer (exact or inexact) above a real number
Purpose: to determine whether some value is complex
Purpose: to compute the conjugate of a complex number
Purpose: to compute the cosine of a number (radians)
cosh : (number -> number) |
Purpose: to compute the hyperbolic cosine of a number
Purpose: to compute the current time in seconds elapsed (since a platform-specific starting date)
Purpose: to compute the denominator of a rational
Purpose: Euler’s number
even? : (integer -> boolean) |
Purpose: to determine if some integer (exact or inexact) is even or not
Purpose: to convert an exact number to an inexact one
Purpose: to determine whether some number is exact
Purpose: to compute e raised to a number
expt : (number number -> number) |
Purpose: to compute the power of the first to the second number
floor : (real -> integer) |
Purpose: to determine the closest integer (exact or inexact) below a real number
gcd : (integer integer ... -> integer) |
Purpose: to compute the greatest common divisior of two integers (exact or inexact)
Purpose: to extract the imaginary part from a complex number
Purpose: to approximate an inexact number by an exact one
Purpose: to determine whether some number is inexact
Purpose: to lookup the character that corresponds to the given integer (exact only!) in the ASCII table (if any)
Purpose: to compute the integer (exact or inexact) square root of a number
Purpose: to determine whether some value is an integer (exact or inexact)
lcm : (integer integer ... -> integer) |
Purpose: to compute the least common multiple of two integers (exact or inexact)
Purpose: to compute the base-e logarithm of a number
Purpose: to determine the magnitude of a complex number
Purpose: to create a complex from a magnitude and angle
Purpose: to create a complex from a real and an imaginary part
max : (real real ... -> real) |
Purpose: to determine the largest number
min : (real real ... -> real) |
Purpose: to determine the smallest number
modulo : (integer integer -> integer) |
Purpose: to find the remainder of the division of the first number by the second; try (modulo 4 3) (modulo 4 -3)
Purpose: to determine if some value is strictly smaller than zero
Purpose: to convert a number to a string
Purpose: to determine whether some value is a number
Purpose: to compute the numerator of a rational
odd? : (integer -> boolean) |
Purpose: to determine if some integer (exact or inexact) is odd or not
Purpose: the ratio of a circle’s circumference to its diameter
Purpose: to determine if some value is strictly larger than zero
Purpose: to divide the first integer (exact or inexact) into the second; try (quotient 3 4) and (quotient 4 3)
random | : | (case-> | (integer -> integer) | (-> (and/c real inexact? (>/c 0) (</c 1)))) |
|
|
Purpose: to generate a random natural number less than some given integer, or to generate a random inexact number between 0.0 and 1.0 exclusive
Purpose: to determine whether some value is a rational number
Purpose: to extract the real part from a complex number
Purpose: to determine whether some value is a real number
Purpose: to determine the remainder of dividing the first by the second integer (exact or inexact)
round : (real -> integer) |
Purpose: to round a real number to an integer (rounds to even to break ties)
sgn : (real -> (union 1 1.0 0 0.0 -1 -1.0)) |
Purpose: to compute the sign of a real number
Purpose: to compute the sine of a number (radians)
sinh : (number -> number) |
Purpose: to compute the hyperbolic sine of a number
Purpose: to compute the square of a number
sqrt : (number -> number) |
Purpose: to compute the square root of a number
sub1 : (number -> number) |
Purpose: to compute a number one smaller than a given number
Purpose: to compute the tangent of a number (radians)
zero? : (number -> boolean) |
Purpose: to determine if some value is zero or not
5.16.2 Booleans
Purpose: to determine whether two booleans are equal
Purpose: to determine whether some value is a boolean
Purpose: to determine whether a value is false
not : (boolean -> boolean) |
Purpose: to compute the negation of a boolean value
5.16.3 Symbols
Purpose: to convert a symbol to a string
Purpose: to determine whether two symbols are equal
Purpose: to determine whether some value is a symbol
5.16.4 Lists
append : ((listof any) ... -> (listof any)) |
Purpose: to create a single list from several
assoc : (any (listof any) -> (listof any) or false) |
Purpose: to produce the first element on the list whose first is equal? to v; otherwise it produces false
assq | : | (X | (listof (cons X Y)) | -> | (union false (cons X Y))) |
|
|
Purpose: to determine whether some item is the first item of a pair in a list of pairs
caaar | : | ((cons | (cons (cons W (listof Z)) (listof Y)) | (listof X)) | -> | W) |
|
|
Purpose: to select the first item of the first list in the first list of a list
caadr | : | ((cons | (cons (cons W (listof Z)) (listof Y)) | (listof X)) | -> | (listof Z)) |
|
|
Purpose: to select the rest of the first list in the first list of a list
caar : ((cons (cons Z (listof Y)) (listof X)) -> Z) |
Purpose: to select the first item of the first list in a list
cadar | : | ((cons (cons W (cons Z (listof Y))) (listof X)) | -> | Z) |
|
|
Purpose: to select the second item of the first list of a list
Purpose: to select the fourth item of a non-empty list
caddr : ((cons W (cons Z (cons Y (listof X)))) -> Y) |
Purpose: to select the third item of a non-empty list
cadr : ((cons Z (cons Y (listof X))) -> Y) |
Purpose: to select the second item of a non-empty list
car : ((cons Y (listof X)) -> Y) |
Purpose: to select the first item of a non-empty list
cdaar | : | ((cons | (cons (cons W (listof Z)) (listof Y)) | (listof X)) | -> | (listof Z)) |
|
|
Purpose: to select the rest of the first list in the first list of a list
cdadr | : | ((cons W (cons (cons Z (listof Y)) (listof X))) | -> | (listof Y)) |
|
|
Purpose: to select the rest of the first list in the rest of a list
cdar | : | ((cons (cons Z (listof Y)) (listof X)) | -> | (listof Y)) |
|
|
Purpose: to select the rest of a non-empty list in a list
cddar | : | ((cons (cons W (cons Z (listof Y))) (listof X)) | -> | (listof Y)) |
|
|
Purpose: to select the rest of the rest of the first list of a list
cdddr | : | ((cons W (cons Z (cons Y (listof X)))) | -> | (listof X)) |
|
|
Purpose: to select the rest of the rest of the rest of a list
cddr : ((cons Z (cons Y (listof X))) -> (listof X)) |
Purpose: to select the rest of the rest of a list
cdr : ((cons Y (listof X)) -> (listof X)) |
Purpose: to select the rest of a non-empty list
cons : (X (listof X) -> (listof X)) |
Purpose: to construct a list
Purpose: to determine whether some value is a constructed list
Purpose: to select the eighth item of a non-empty list
Purpose: to determine whether some value is the empty list
fifth : ((listof Y) -> Y) |
Purpose: to select the fifth item of a non-empty list
first : ((cons Y (listof X)) -> Y) |
Purpose: to select the first item of a non-empty list
Purpose: to select the fourth item of a non-empty list
length : ((listof any) -> number) |
Purpose: to compute the number of items on a list
list : (any ... -> (listof any)) |
Purpose: to construct a list of its arguments
list* : (any ... (listof any) -> (listof any)) |
Purpose: to construct a list by adding multiple items to a list
list-ref : ((listof X) natural-number -> X) |
Purpose: to extract the indexed item from the list
Purpose: to determine whether some value is a list
make-list : (natural-number any -> (listof any)) |
Purpose: (make-list k x) constructs a list of k copies of x
member : (any (listof any) -> boolean) |
Purpose: to determine whether some value is on the list (comparing values with equal?)
member? : (any (listof any) -> boolean) |
Purpose: to determine whether some value is on the list (comparing values with equal?)
memq : (any (listof any) -> (union false list)) |
Purpose: to determine whether some value is on some list if so, it produces the suffix of the list that starts with x if not, it produces false. (It compares values with the eq? predicate.)
memv : (any (listof any) -> (union false list)) |
Purpose: to determine whether some value is on the list if so, it produces the suffix of the list that starts with x if not, it produces false. (it compares values with the eqv? predicate.)
Purpose: the empty list
Purpose: to determine whether some value is the empty list
Purpose: to determine whether some value is a constructed list
remove : (any (listof any) -> (listof any)) |
Purpose: to construct a list like the given one with the first occurrence of the given item removed (comparing values with equal?)
rest : ((cons Y (listof X)) -> (listof X)) |
Purpose: to select the rest of a non-empty list
Purpose: to create a reversed version of a list
second : ((cons Z (cons Y (listof X))) -> Y) |
Purpose: to select the second item of a non-empty list
Purpose: to select the seventh item of a non-empty list
sixth : ((listof Y) -> Y) |
Purpose: to select the sixth item of a non-empty list
third : ((cons W (cons Z (cons Y (listof X)))) -> Y) |
Purpose: to select the third item of a non-empty list
5.16.5 Posns
Purpose: to construct a posn
Purpose: signature for posns
Purpose: to extract the x component of a posn
Purpose: to extract the y component of a posn
posn? : (anything -> boolean) |
Purpose: to determine if its input is a posn
Purpose: to update the x component of a posn
Purpose: to update the x component of a posn
5.16.6 Characters
Purpose: to lookup the number that corresponds to the given character in the ASCII table (if any)
Purpose: to determine whether a character represents an alphabetic character
Purpose: to determine whether a character precedes another (or is equal to it) in a case-insensitive manner
Purpose: to determine whether a character precedes another in a case-insensitive manner
Purpose: to determine whether two characters are equal in a case-insensitive manner
Purpose: to determine whether a character succeeds another (or is equal to it) in a case-insensitive manner
Purpose: to determine whether a character succeeds another in a case-insensitive manner
Purpose: to determine the equivalent lower-case character
Purpose: to determine whether a character is a lower-case character
Purpose: to determine whether a character represents a digit
Purpose: to determine the equivalent upper-case character
Purpose: to determine whether a character is an upper-case character
Purpose: to determine whether a character represents space
char<=? : (char char char ... -> boolean) |
Purpose: to determine whether a character precedes another (or is equal to it)
char<? : (char char char ... -> boolean) |
Purpose: to determine whether a character precedes another
char=? : (char char char ... -> boolean) |
Purpose: to determine whether two characters are equal
char>=? : (char char char ... -> boolean) |
Purpose: to determine whether a character succeeds another (or is equal to it)
char>? : (char char char ... -> boolean) |
Purpose: to determine whether a character succeeds another
Purpose: to determine whether a value is a character
5.16.7 Strings
explode : (string -> (listof string)) |
Purpose: to translate a string into a list of 1-letter strings
format : (string any ... -> string) |
Purpose: to format a string, possibly embedding values
implode : ((listof string) -> string) |
Purpose: to concatenate the list of 1-letter strings into one string
Purpose: to convert an integer in [0,55295] or [57344 1114111] to a 1-letter string
Purpose: to convert a s list of characters into a string
Purpose: to produce a string of given length from a single given character
Purpose: to replicate the given string
Purpose: (string c1 c2 ...) builds a string
Purpose: to convert a 1-letter string to an integer in [0,55295] or [57344, 1114111]
Purpose: to convert a string into a list of characters
Purpose: to convert a string into a number, produce false if impossible
Purpose: to convert a string into a symbol
Purpose: to determine whether all ’letters’ in the string are alphabetic
Purpose: to juxtapose the characters of several strings
Purpose: to determine whether one string alphabetically precedes another (or is equal to it) in a case-insensitive manner
Purpose: to determine whether one string alphabetically precedes another in a case-insensitive manner
Purpose: to compare two strings character-wise in a case-insensitive manner
Purpose: to determine whether one string alphabetically succeeds another (or is equal to it) in a case-insensitive manner
Purpose: to determine whether one string alphabetically succeeds another in a case-insensitive manner
Purpose: to copy a string
Purpose: to extract the ith 1-letter substring from the given one
Purpose: to determine the length of a string
Purpose: to determine whether all ’letters’ in the string are lower case
Purpose: to determine whether all ’letters’ in the string are numeric
Purpose: to extract the i-the character from a string
Purpose: to determine whether all ’letters’ in the string are upper case
Purpose: to determine whether all ’letters’ in the string are white space
string<=? : (string string string ... -> boolean) |
Purpose: to determine whether one string alphabetically precedes another (or is equal to it)
string<? : (string string string ... -> boolean) |
Purpose: to determine whether one string alphabetically precedes another
string=? : (string string string ... -> boolean) |
Purpose: to compare two strings character-wise
string>=? : (string string string ... -> boolean) |
Purpose: to determine whether one string alphabetically succeeds another (or is equal to it)
string>? : (string string string ... -> boolean) |
Purpose: to determine whether one string alphabetically succeeds another
Purpose: to determine whether a value is a string
Purpose: to extract the substring starting at a 0-based index up to the second 0-based index (exclusive)
5.16.8 Images
Purpose: to determine whether two images are equal
Purpose: to determine whether a value is an image
5.16.9 Misc
=~ : (number number non-negative-real -> boolean) |
Purpose: to check whether two numbers are within some amount (the third argument) of either other
Purpose: to return the current “time” in fixnum milliseconds (possibly negative)
Purpose: the end-of-file value
Purpose: to determine whether some value is the end-of-file value
eq? : (any any -> boolean) |
Purpose: to determine whether two values are equivalent from the computer’s perspective (intensional)
Purpose: to determine whether two values are structurally equal where basic values are compared with the eqv? predicate
equal~? : (any any non-negative-real -> boolean) |
Purpose: to compare like equal? on the first two arguments, except using =~ in the case of numbers
eqv? : (any any -> boolean) |
Purpose: to determine whether two values are equivalent from the perspective of all functions that can be applied to it (extensional)
error : (any ... -> void) |
Purpose: to signal an error, combining the given values into an error message.
If any of the values’ printed representations is too long, it is truncated and “...” is put into the string. If the first value is a symbol, it is treated specially; it is suffixed with a colon and a space (the intention is that the symbol is the name of the function signalling the error).
Purpose: to exit the running program
Purpose: to find the delayed value; see also delay
Purpose: to generate a new symbol, different from all symbols in the program
Purpose: to return the argument unchanged
Purpose: to determine if a value is delayed
sleep : (-> positive-number void) |
Purpose: to cause the program to sleep for the given number of seconds
Purpose: to determine whether some value is a structure
Purpose: produces a void value
Purpose: to determine if a value is void
5.16.10 Numbers (relaxed conditions)
* : (number ... -> number) |
Purpose: to multiply all given numbers
+ : (number ... -> number) |
Purpose: to add all given numbers
- : (number ... -> number) |
Purpose: to subtract from the first all remaining numbers
/ : (number ... -> number) |
Purpose: to divide the first by all remaining numbers
5.16.11 Higher-Order Functions
andmap : ((X -> boolean) (listof X) -> boolean) |
Purpose: (andmap p (list x-1 ... x-n)) = (and (p x-1) ... (p x-n))
apply | : | ((X-1 ... X-N -> Y) | X-1 | ... | X-i | (list X-i+1 ... X-N) | -> | Y) |
|
|
Purpose: to apply a function using items from a list as the arguments
argmax : ((X -> real) (listof X) -> X) |
Purpose: to find the (first) element of the list that maximizes the output of the function
argmin : ((X -> real) (listof X) -> X) |
Purpose: to find the (first) element of the list that minimizes the output of the function
Purpose: (build-list n f) = (list (f 0) ... (f (- n 1)))
Purpose: (build-string n f) = (string (f 0) ... (f (- n 1)))
compose | : | ((Y-1 -> Z) | ... | (Y-N -> Y-N-1) | (X-1 ... X-N -> Y-N) | -> | (X-1 ... X-N -> Z)) |
|
|
Purpose: to compose a sequence of procedures into a single procedure
filter : ((X -> boolean) (listof X) -> (listof X)) |
Purpose: to construct a list from all those items on a list for which the predicate holds
foldl : ((X Y -> Y) Y (listof X) -> Y) |
Purpose: (foldl f base (list x-1 ... x-n)) = (f x-n ... (f x-1 base))
foldr : ((X Y -> Y) Y (listof X) -> Y) |
Purpose: (foldr f base (list x-1 ... x-n)) = (f x-1 ... (f x-n base))
for-each : ((any ... -> any) (listof any) ... -> void) |
Purpose: to apply a function to each item on one or more lists for effect only
map : ((X ... -> Z) (listof X) ... -> (listof Z)) |
Purpose: to construct a new list by applying a function to each item on one or more existing lists
memf | : | ((X -> boolean) | (listof X) | -> | (union false (listof X))) |
|
|
Purpose: to determine whether the first argument produces true for some value in the second argument
ormap : ((X -> boolean) (listof X) -> boolean) |
Purpose: (ormap p (list x-1 ... x-n)) = (or (p x-1) ... (p x-n))
Purpose: to determine if a value is a procedure
quicksort : ((listof X) (X X -> boolean) -> (listof X)) |
Purpose: to construct a list from all items on a list in an order according to a predicate
sort : ((listof X) (X X -> boolean) -> (listof X)) |
Purpose: to construct a list from all items on a list in an order according to a predicate
5.16.12 Reading and Printing
Purpose: to print the argument to stdout (without quotes on symbols and strings, etc.)
Purpose: to print a newline to stdout
Purpose: like write, but with standard newlines and indentation
Purpose: to print the argument as a value to stdout
printf : (string any ... -> void) |
Purpose: to format the rest of the arguments according to the first argument and print it to stdout
Purpose: to read input from the user
Purpose: to open the named input file and to extract all input from there
Purpose: to turn the given string into input for read* operations
Purpose: to open the named output file and to put all output there
Purpose: to produce a string from all write/display/print operations
Purpose: to print the argument to stdout (in a traditional style that is somewhere between print and display)
5.16.13 Vectors
Purpose: to construct a vector
Purpose: to construct a vector
vector : (X ... -> (vector X ...)) |
Purpose: to construct a vector
Purpose: to determine the length of a vector
Purpose: to extract an element from a vector
Purpose: to update a vector
Purpose: to determine if a value is a vector
5.16.14 Boxes
Purpose: to construct a box
Purpose: to determine if a value is a box
Purpose: to update a box
Purpose: to extract the boxed value
5.16.15 Hash Tables
Purpose: to copy a hash table
Purpose: to determine the number of keys mapped by a hash table
Purpose: to determine if a hash table uses eq? for comparisions
Purpose: to determine if a hash table uses equal? for comparisions
Purpose: to determine if a hash table uses eqv? for comparisions
Purpose: to apply a function to each mapping of a hash table for effect only
Purpose: to determine if a key is associated with a value in a hash table
hash-map : ((hash X Y) (X Y -> A) -> (listof A)) |
Purpose: to construct a new list by applying a function to each mapping of a hash table
hash-ref | : | (case-> | ((hash X Y) X -> Y) | ((hash X Y) X Y -> Y) | ((hash X Y) X (-> Y) -> Y)) |
|
|
Purpose: to extract the value associated with a key from a hash table; the three argument case allows a default value or default value computation
hash-ref! | : | (case-> | ((hash X Y) X Y -> Y) | ((hash X Y) X (-> Y) -> Y)) |
|
|
Purpose: to extract the value associated with a key from a mutable hash table; if the key does not have an mapping, the third argument is used as the value (or used to compute the value) and is added to the hash table associated with the key
Purpose: to construct an immutable hash table with one less mapping than an existing immutable hash table
Purpose: to remove an mapping from a mutable hash table
hash-set : ((hash X Y) X Y -> (hash X Y)) |
Purpose: to construct an immutable hash table with one new mapping from an existing immutable hash table
Purpose: to update a mutable hash table with a new mapping
hash-update | : | (case-> | ((hash X Y) X (Y -> Y) -> (hash X Y)) | ((hash X Y) X (Y -> Y) Y -> (hash X Y)) | ((hash X Y) X (Y -> Y) (-> Y) -> (hash X Y))) |
|
|
Purpose: to compose hash-ref and hash-set to update an existing mapping; the third argument is used to compute the new mapping value; the fourth argument is used as the third argument to hash-ref
hash-update! | : | (case-> | ((hash X Y) X (Y -> Y) -> void) | ((hash X Y) X (Y -> Y) Y -> void) | ((hash X Y) X (Y -> Y) (-> Y) -> void)) |
|
|
Purpose: to compose hash-ref and hash-set! to update an existing mapping; the third argument is used to compute the new mapping value; the fourth argument is used as the third argument to hash-ref
Purpose: to determine if a value is a hash table
make-hash | : | (case-> | (-> (hash X Y)) | ((listof (list X Y)) -> (hash X Y))) |
|
|
Purpose: to construct a mutable hash table from an optional list of mappings that uses equal? for comparisions
make-hasheq | : | (case-> | (-> (hash X Y)) | ((listof (list X Y)) -> (hash X Y))) |
|
|
Purpose: to construct a mutable hash table from an optional list of mappings that uses eq? for comparisions
make-hasheqv | : | (case-> | (-> (hash X Y)) | ((listof (list X Y)) -> (hash X Y))) |
|
|
Purpose: to construct a mutable hash table from an optional list of mappings that uses eqv? for comparisions
Purpose: to construct an immutable hash table from an optional list of mappings that uses equal? for comparisions
Purpose: to construct an immutable hash table from an optional list of mappings that uses eq? for comparisions
Purpose: to construct an immutable hash table from an optional list of mappings that uses eqv? for comparisions