This reference manual describes all the builtin syntax, procedures, and values in the language that are defined by default. --edit docs
(define id expr) Syntax
Set id to the result of expr.
(set! id expr) Syntax
Set id to the result of expr if id is already defined. If id is not defined, raise an error.
(lambda args body) Syntax
Produces a procedure that accepts args arguments and runs body when called.
(λ args body) Syntax
Clone of lambda.
(define/c (proc-bind [id-binding contract]... )) Syntax
Define a procedure with contracts.
(let ([id val-expr] ...) body)) Syntax
Evaluates the val-exprs left-to-right, creating a new location for each id, and places the values into the locations. It then evaluates the bodys, in which the ids are bound.
(let* ([id val-expr] ...) body)) Syntax
Like let, but evaluates the val-exprs one by one, creating a location for each id as soon as the value is available. The ids are bound in the remaining val-exprs as well as in the body.
(if test-expr then-expr else-expr) Syntax
Evaluates test-expr. If #t then evaluate then-expr else evaluate else-expr. An error will be raised if evaluated test-expr is not a bool?.
(when test-expr body) Syntax
Evaluates test-expr. If #t then evaluate body else do nothing. An error will be raised if evaluated test-expr is not a bool?.
(cond [test-clause then-body]... [else then-body]) Syntax
Evaluate each cond-clause if the clause is evaluated to #t then evaluate and return then-body. If the clause is #f continue to the next clause. If there are no clauses left return #<void>. If the last test-clause is else then its evaluated then-body.
(case val-expr case-clause ...) Syntax
Evaluates val-expr and uses the result to choose a case-clause. The selected clause is the first datum whose quote form is equal? to the result of val-expr. If no case-clause is choosen, then #<void> is returned, unless there is an else clause, in that case return its body.
A case-clause that starts with else must be the last case-clause.
(for ([id seq-expr] ...) body) Syntax
Loop over seq-expr by setting the variable id to the nth item of seq-expr and evaluating body.
(for-items [key value hash-id] body) Syntax
Loop over key-value pairs of hash-id, which should be a hash?.
Returns #t if v1 and v2 are the same type and have the same value, #f otherwise.
Returns #t if v1 and v2 refer to the same object in memory, #f otherwise.
Returns #t if v is #t or #f, #f otherwise.
true : bool? Value
An alias for #t.
false : bool? Value
An alias for #f.
Returns #t if v is a number, #f otherwise.
Returns #t if v is a real number, #f otherwise.
Returns #t if v is an integer, #f otherwise.
Returns #t if v is a float, #f otherwise.
Returns #t if v is a fraction (a rational number), #f otherwise.
Returns #t if v is an complex number, #f otherwise.
Returns #t if v is an integer and v is >= 0, #f otherwise.
Returns #t if v is an integer and v is >= 1, #f otherwise.
Returns #t if v is a float and v is >= 0 and <= 1, #f otherwise.
Returns (= z 0)
Returns (> x 0)
Returns (< x 0)
Returns (zero? (mod n 2))
Returns (not (even? n))
Return the sum of zs. Add from left to right. If no arguments are provided the result is 0.
When no ws are applied return (- 0 z)
, otherwise return the subtraction of ws of z.
Return the product of zs. If no zs are supplied the result is 1.
Returns the division of z by the ws. If no ws are given, returns (/ 1 z)
.
Returns the integer division of n by the ms.
Return the modulo of n and m.
Clone of mod.
Returns (+ z 1)
.
Returns (- z 1)
.
(incf id [delta 1]) Syntax
Mutate id by adding the evaluated result of delta. If delta is not specified, then add 1 to id.
(decf id [delta 1]) Syntax
Mutate id by subtracting the evaluated result of delta. If delta is not specified, then subtract 1 from id.
Returns #t if all arguments are numerically equal, #f otherwise.
Returns #t if x is less than y, #f otherwise.
Returns #t if x is less than or equal to y, #f otherwise.
Returns #t if x is greater than y, #f otherwise.
Returns #t if x is greater than or equal to y, #f otherwise.
Returns the absolute value of x.
Returns largest value of the xs.
Returns smallest value of the xs.
Returns the real part of z.
Returns the imaginary part of z.
Returns the closest integer to x resolving ties in favor of even numbers.
Returns z raised to the w power.
Returns the square root of z.
(import module) Syntax
Imports a module
Imported with (import math)
.
Returns the smallest integer bigger than x.
Returns the largest integer less than x.
Returns Euler's number raised to the x power.
Returns the natural logarithm of x.
If b is provided it serves as an alternative base.
e : 2.718281828459045 Value
Euler's number.
Returns the sine of z in radians.
Returns the cosine of z in radians.
Returns the tangent of z in radians.
Returns the arc sine of z.
Returns the arc cosine of z.
Returns the arc tangent of z.
pi : 3.141592653589793 Value
The ratio of a circle's circumference to its diameter.
tau : 6.283185307179586 Value
The ratio of a circle's circumference to its radius.
Returns #t if v is a symbol, #f otherwise.
Returns a new string whose characters are the same as in sym.
Returns a symbol whose characters are the same as str.
Returns #t if v is a string, #f otherwise.
Returns #t if v is a char, #f otherwise.
Returns a new string from the given chars.
Returns a new string concatenated from the given strs
(&= id delta) Syntax
Mutate id by concatenating the evaluated result of delta.
Returns a string whose characters are the upcase conversion of the characters in str in the C locale.
Like upper, but for downcase conversion.
Like upper, but for titlecase conversion.
Returns #t if str starts with w, #f otherwise.
Returns #t if str ends with w, #f otherwise.
Returns str with its leading and tailing whitespace stripped out.
Returns str will all ws replaced with zs.
Returns str will all ws replaced with zs up until count.
Returns a vector of strings split from str by 'by.
Returns str concatenated n times.
Returns a new string with strs joined between with sep.
Returns a new string with the file extension replaced with ext.
Returns the corresponding int to the given char.
Returns the character corresponding to k.
Returns z as a string.
Converts all vs to a string using display with "" as the joiner.
Converts all vs to a string using display with " " as the joiner.
Converts all v to a string using print with " " as the joiner.
Returns #t if v is a keyword, #f otherwise.
Returns the string from the given keyword, not including the leading hash colon.
Returns the keyword from the given str.
Return #t if v is a list (an immutable collection of elements), #f otherwise.
Returns a new list with the vs as the elements.
Returns a new list with all the arguments appended in order.
Returns #t if v is a vector (a mutable, resizable collection of elements), #f otherwise.
Returns a new vector with the v args filled with its slots in order.
Returns a new vector with size slots all filled with vs.
Append v to the end of vec.
Remove the last element of vec and return it.
Set slot pos of vec to v.
Returns a new vector with all elements of vecs appended in order.
Modify vec so that all elements of vec2s are appended to the end of vec in order.
Returns a newly sorted vector.
Modifies vec by sorting in place.
Returns a new vector with characters contained in str.
Returns #t if v is an array, #f otherwise.
Returns a freshly allocated array with dtype as its datatype and the v args as its values filled in order.
Returns a freshly allocated array with dtype as its datatype and the value v filled.
Returns a new copy of arr.
Modify arr by setting start to stop into the value v.
Returns the number of non-zeros in arr.
Returns #t if v is an array with 'bool as its datatype, #f otherwise.
(bool-array v ...) → bool-array? Procedure
v : nat?
Returns a new boolean array with v as its values.
Returns a new bool-array? with left and right margin applied.
(and first-expr rest-expr ...) Syntax
Evaluate first-expr if the result is a bool-array? evaluate all rest-exprs and return the logical-and of all arrays. If the result is #f evaluate rest-expr one at a time. Return immediately if any arg is #f, return #t if all values are #t.
(or first-expr rest-expr ...) Syntax
Evaluate first-expr if the result is a bool-array? evaluate all rest-exprs and return the logical-and of all arrays. If the result is #t evaluate rest-expr one at a time. Return immediately if any arg is #t, return #f if all values are #f.
(xor expr1 expr2) → (or/c bool? bool-array?) Procedure
expr1 : (or/c bool? bool-array?)
expr2 : (or/c bool? bool-array?)
Returns a new boolean or boolean-array based on the exclusive-or of expr1 and expr2. expr2 must be the same type as expr1.
(not h) → (or/c bool? bool-array?) Procedure
h : (or/c bool? bool-array?)
Returns the inverse of h.
Turn all 0 runs that are less than x in length to 1s. 0s represent cuts, 1s represent clips.
Turn all 1 runs that are less than x in length to 0s
Turn all 0 runs that are greater than x in length to 1s
Turn all 1 runs that are more than x in length to 0s
all : 'all Value
The symbol 'all. Exists for backwards compatibility for older auto-editor versions.
Returns #t if v is a range object, #f otherwise.
Returns a range object.
Returns a new vector based on rng.
Returns #t if v is a vector array string hash or range, #f otherwise.
Returns #t if v is a vector array string or range, #f otherwise.
Returns the length of iter.
Returns #t if x is in seq, #f otherwise.
Returns the element of seq at position pos where the first element is at position 0. Negative positions are allowed.
Returns seq in reverse order.
Returns the elements of seq from start inclusively to stop exclusively. If step is negative then stop is inclusive and start is exclusive.
Returns the largest value of v.
Returns the smallest value of v.
Returns #t if v is a hash table, #f otherwise.
Returns a newly constructed hash map from key-value pairs.
Returns the value for key in hash.
Set key to v in hash, overwriting any existing mappings.
Returns #t if key is in the hash map, #f otherwise.
Updates the value mapped by key in hash by applying updater to the value. The value returned by updater becomes the new mapping for key, overwriting the original value in hash.
Removes any existing mapping for key in hash.
Returns #t if v is an output port, #f otherwise.
(open-output-file path) → output-port? Procedure
path : string?
Opens the file specified by path for output.
(close-port out) → void? Procedure
out : output-port?
Flushes, then closes the port out. The port is now incapable of delivering or accepting data. This has no effect if the port has already been closed.
(closed? v) → bool? Procedure
v : output-port?
Returns #t if v is a closed port, #f otherwise.
Display datum like REPL does.
Display datum like print but with a newline character.
Display datum to stdout.
Display datum to stdout with a newline character.
(begin datum ...) → any Procedure
datum : any
Evaluates all arguments and returns the last one.
Raises error if expr is not #t.
Raises an exception with msg as the message.
Adds a delay of time seconds.
Executes a Unix-like or Windows shell command synchronously. Returns #t if successful, #f otherwise.
Executes a Unix-like or Windows shell command synchronously. Returns #t if successful, #f otherwise.
Returns #t if v is #<void>, #f otherwise.
Returns the constant #<void>. All v arguments are ignored.
Returns #t if v is a procedure, #f otherwise.
Returns #t if v is a contract, #f otherwise. A contract is either a bool?, number?, string?, symbol? literal, or a predicate.
Always returns #t regardless of the value of v.
Returns a new sequence with the results of proc applied to each element.
Applies proc given seq as its arguments.
Takes any number of contracts and returns a contract predicate that accept values that satisfies all contracts.
Takes any number of contracts and returns a contract predicate that accept values that can satisfy one or more contracts.
Takes one contract and returns a contract that accepts a value that satisfies the opposite of the given contract.
Returns a new contract that requires the input to be real? and >= than n.
Returns a contract that requires the input a real number between n and m or equal to one of them.
(quote body) Syntax
Returns body as its "literalized" form, a constant value with its binding names copied.
Returns #t if the variable corresponding to sym is defined in the current environment, #f otherwise.
(rename original new) Syntax
Move the original identifier to the new identifier. Works for both procedures and syntaxes.
(delete identifier) Syntax
Deletes identifier from the environment.
Allows running arbitrary, dynamically generated code. Effective the opposite of quote.
(class name [id contract?]...) Syntax
Creates a object initiator and a predicate to identify that object. Example:
(class person [name string?] [age nat?])
(define alyssa (person "Alyssa P." 23))
alyssa.name ; returns "Alyssa P."
alyssa.age ; returns 23
(person? alyssa) ; returns #t
Class objects are mutable(incf alyssa.age) ; Increase age by 1
(@r obj attr) Syntax
Returns the specified attribute on the object. Users are not expected to directly use this special form. Instead, use the `.` syntax.
(define a 10)
a.incf ; turns into (@r a incf)