Array
An ordered collection of values. Arrays can have items added or removed from them at will, changing their size dynamically.
Definition: Primitive type.
Uses mixins:
append:
Adds a new item to the end of this array.
append:
The new item to add.
appendAll:
Appends all elements from an enumerable to this array.
appendAll:
The enumerable to append items from.
delete:
Deletes an item at a specific index, and shifts the array elements down to
compensate. If the array does not cover the index, returns null
.
delete:
The zero-indexed index to delete.
Returns:
The deleted item, or
null
if there was no item at that index.
first
Returns the first item of this array.
Returns:
The first item of the array, or
null
if it is empty.
forEach:
Calls a function for each element of the array, passing it as a parameter.
forEach:
The block to call, which should accept one parameter.
get:
Gets an item from this array.
get:
The zero-indexed index of the item to get.
Returns:
The item, or
null
if the index is out of bounds.
getN:
Indexes into a multidimensional array. Calls get:
on this array and the successive arrays
returned by that call, using each index in the given array.
getN:
The array of indexes to use.
Returns:
The item retrieved.
insert:at:
Inserts a new item at a specific index within this array. If the array is not long
enough, it is extended with null
s so that the new item is at the end of the array.
insert:
The new item to add.
at:
The zero-indexed index at which to insert it.
isEmpty
Checks if this array is empty.
Returns:
true
if this array is empty, orfalse
otherwise.
last
Returns the last item of this array.
Returns:
The last item of the array, or
null
if it is empty.
length
The length of the array.
Returns:
The number of items in the array.
static
new
Constructs a new array.
Returns:
A new array with length 0.
static
newFrom:length:
Constructs a new array by repeatedly executing a block to obtain elements.
newFrom:
The block to execute to get elements.
length:
The number of times to repeat the element.
Returns:
A new array.
static
newOf:length:
Constructs a new array by repeating one element.
newOf:
The element to repeat.
length:
The number of times to repeat the element.
Returns:
A new array.
pop
Deletes the last item of this array and returns it. If the array is empty, returns null
.
Returns:
The last (now-deleted) item of this array, or
null
.
set:value:
Sets an item in this array. If the given index does not already exist in the array,
it is extended with null
s to match the required length.
set:
The zero-indexed index of the item to set.
value:
The value to write into the array.
setN:value:
Sets an index in a multidimensional array. Calls get:
on this array and the successive arrays
returned by that call, using each index in the given array up until the last one, where
set:
is called instead.
setN:
The array of indexes to use.
value:
The value to set the last index to.
Block
The type of a block created with [ ... ]
syntax. Blocks are objects representing snippets
of code which can be executed with parameters, optionally performing pattern matching on
those parameters, as well as capturing local variables from their scope.
Definition: Primitive type.
arity
How many arguments this block takes.
Returns:
An integer representing the number of arguments this block takes.
call
Calls this block with no arguments.
Returns:
The result of the block.
call:
Calls this block with one argument.
call
The single argument to pass.
Returns:
The result of the block.
callWith:
Calls this block with the given array of arguments.
callWith:
The array of arguments to pass to the block.
Returns:
The result of the block.
whileTrue:
Repeatedly executes another block (the body) while this block (the condition)
continues to return true
. If the condition returns false
the first time it is
executed, the body is never executed.
whileTrue:
The block to execute as a condition.
Boolean
Logical true and false values.
Definition: Enum with variants:
False
True
and:
Computes boolean AND with another boolean.
and:
The other boolean.
Returns:
true
if both booleans aretrue
, otherwisefalse
.
andAlso:
Computes boolean AND with the result of a function which returns a boolean. The function is only-executed if logically necessary; that is, this method is short-circuting.
andAlso:
The function which returns the other boolean.
Returns:
true
if both booleans aretrue
, otherwisefalse
.
ifFalse:
Executes the block if this boolean is false
.
ifFalse:
The block to execute.
ifTrue:
Executes a block if this is true
.
ifTrue:
The block to execute if this is
true
.Returns:
This boolean.
ifTrue:else:
Executes one block if this boolean is true
, or another if it is false
.
ifTrue:
The block to execute in the
true
case.
else:
The block to execute in the
false
case.Returns:
The result of whichever block was executed.
not
Logically negates this boolean.
Returns:
true
if this isfalse
, orfalse
if this istrue
.
or:
Computes boolean OR with another boolean.
or:
The other boolean.
Returns:
true
if either boolean istrue
, otherwisefalse
.
orElse:
Computes boolean OR with the result of a function which returns a boolean. The function is only-executed if logically necessary; that is, this method is short-circuting.
andAlso:
The function which returns the other boolean.
Returns:
true
if either boolean istrue
, otherwisefalse
.
toMatch
Converts this boolean to a Match
, where true
is a hit with value null
, and false
is
a miss.
Returns:
The
Match
instance.
Console
An interface to standard input and output streams on the host machine.
Definition: Primitive type.
static
input
Reads a line of input from the console.
Returns:
The line as a string.
static
print:
Prints an object to the console, with no trailing newline.
Additionally, flushes the console buffer, to ensure that the output is actually displayed, since many consoles will not usually show content until a newline is printed.
print:
The object to print.
static
println:
Prints an object to the console, followed by a newline.
println:
The object to print.
Dictionary
A data structure which maps unique keys to values.
Objects used as keys must implement Hashable
and Equatable
.
Items in the dictionary are categorised by the Hashable hash
value of their keys, but also
compared for equality with Equatable equals:
. This means that keys a
and b
where
a hash equals: b hash
but a notEquals: b
will be treated as distinct keys.
Definition: Struct with fields:
buckets
length
Uses mixins:
private
bucketFor:
Undocumented.
buckets
Field accessor.
Returns:
The value of
buckets
.
static
unordered
buckets:length:
Constructor.
Returns:
A new instance of
Dictionary
.
containsKey:
Determines whether this dictionary contains the given key.
containsKey:
The key to check for.
Returns:
true
if the key is present in this dictionary,false
otherwise.
delete:
Deletes a key from this dictionary.
delete:
The key to delete.
equals:
Undocumented.
forEach:
Iterates over the key-value pairs of this dictionary. Each element is a two-element array, where the first element is the key and the second is the value.
fn:
The block to execute for each key-value pair, which should take one parameter.
static
fromPairs:
Creates a dictionary from an array of key-value pairs.
fromPairs:
An array of two-element arrays, where the first element is the key and the second is the value.
Returns:
A new dictionary from these values.
get:
Gets a key from this dictionary.
get:
The key to retrieve.
Returns:
The value mapped to that key, or
null
if the key is not present in the dictionary.
get:orInsert:
Gets a key from this dictionary, or if it doesn't exist, inserts it with the given value and returns that.
get:
The key to retrive (or insert if it doesn't exist).
Returns:
The value mapped to that key, or the newly-inserted value.
private
unordered
indexFor:inBucket:
Undocumented.
isEmpty
Checks if this dictionary is empty.
Returns:
true
if this dictionary is empty, orfalse
otherwise.
keys
Returns an array of the keys in this dictionary.
Returns:
This dictionary's keys.
length
Field accessor.
Returns:
The value of
length
.
static
new
Creates an empty dictionary.
Returns:
An empty dictionary.
repr
Undocumented.
resizeBuckets
Re-creates the internal data structure of this dictionary, with a number of buckets equal to double the dictionary's current length.
set:value:
Sets a key in this dictionary to the given value. If the key already exists, its value is replaced.
set:
The key to insert.
value:
The value to map to that key.
values
Returns an array of the values in this dictionary.
Returns:
This dictionary's keys.
Enumerable
Extends a type which represents a container of ordered items to provide various functional programming methods.
Requirements:
forEach:
Definition: Mixin.
all:
Determines whether all elements of the enumerable match a predicate.
any:
The predicate to use, which should accept one parameter.
Returns:
true
if all elements match the predicate,false
otherwise.
any:
Determines whether any element of the enumerable matches a predicate.
any:
The predicate to use, which should accept one parameter.
Returns:
true
if any element matches the predicate,false
otherwise.
chunk:
Partitions this enumerable into an array of chunks of a given size.
If the enumerable is not evenly divisible by the chunk size, the last chunk will be smaller
and contain the leftover elements. (If you would like all chunks to be the same size, see
chunkExact:
.)
chunk:
The size of each chunk.
Returns:
An array of chunk arrays.
chunkExact:
Partitions this enumerable into an array of chunks of a given size.
If the enumerable is not evenly divisible by the chunk size, the remaining elements will
be omitted from the result. (If you would like the last chunk to be smaller, see chunk:
.)
chunk:
The size of each chunk.
Returns:
An array of chunk arrays.
concat:
Converts this enumerable to an array, and concatenates it with another one to produce a larger array.
contains:
Determines whether this enumerable contains an item which equals the given item.
contains:
The item to find.
Returns:
true
if the item is found, orfalse
otherwise.
filter:
Constructs a new array by retaining elements from this enumerable where a block returns
true
.
map:
The block to use as a condition, which should accept one parameter.
Returns:
The new array.
find:
Find the first value in the enumerable matching a predicate.
find:
The predicate to use, which should accept one parameter.
Returns:
The first value matching the predicate, or
null
if none is found.
flatten
Assuming that this enumerable's elements are all themselves enumerables, flattens one layer of enumerable nesting.
Returns:
A flattened array.
groupBy:
Using the given function to compute keys, builds a new dictionary whose values are arrays of elements from this enumerable matching the given key.
s
groupBy: The key function, which should take one parameter.
Returns:
A new grouped dictionary.
index:
Finds the index of the first value in the enumerable matching a predicate.
index:
The predicate to use, which should accept one parameter.
Returns:
The index of the first value matching the predicate, or
null
if none is found.
join
Joins together the strings in this enumerable by repeatedly calling concat:
.
Returns:
The concatenated value.
join:
Joins together the strings in this enumerable with a separator between them, by repeatedly
calling concat:
.
Returns:
The concatenated value.
map:
Constructs a new array by applying a block to each element of this enumerable, in order.
map:
The block to apply, which should accept one parameter.
Returns:
The new array.
max
Finds the largest element of this enumerable, assuming that all elements of the enuemrable
implement Orderable
.
Returns:
The largest element, according to the values'
Orderable
implementation.
maxBy:
Finds the largest key of this enumerable when applying a key function to each element.
minBy:
The key function, which must take one parameter and return an
Orderable
.Returns:
The largest element, according to the values'
Orderable
implementation.
min
Finds the smallest element of this enumerable, assuming that all elements of the enuemrable
implement Orderable
.
Returns:
The smallest element, according to the values'
Orderable
implementation.
minBy:
Finds the smallest key of this enumerable when applying a key function to each element.
minBy:
The key function, which must take one parameter and return an
Orderable
.Returns:
The smallest element, according to the values'
Orderable
implementation.
partition:
Splits this enumerable into two by evaluating the given predicate. The first array contains
all elements for which the predicate returned true
, and the second array contains all
elements for which the predicate returned false
.
partition:
The predicate to use, which should take one parameter.
Returns:
A two-element array, containing
true
andfalse
arrays.
product
Multiplies together the elements in this enumerable, by starting with the integer 1 and
repeatedly calling mul:
.
Returns:
The product value.
reduce:
Reduces this enumerable into a single value, by starting with the enumerable's first element and repeatedly applying a block to it with each successive element of the enumerable.
The block will be called for each item in the enumerable, with the block's result replacing the current accumulator value.
reduce:
The block to apply, which should accept two parameters: the accumulator and the enumerable value.
Returns:
The accumulator value obtained after repeatedly applying the block.
reduce:acc:
Reduces this enumerable into a single value, by starting with an accumulator value and repeatedly applying a block to it with each element of the enumerable.
The block will be called for each item in the enumerable, with the block's result replacing the current accumulator value.
reduce:
The block to apply, which should accept two parameters: the accumulator and the enumerable value.
acc:
The initial accumulator value.
Returns:
The accumulator value obtained after repeatedly applying the block.
reduce:mapAcc:
Reduces this enumerable into a single value, by starting with the enumerable's first element, calling a mapping function on it, and then repeatedly applying a block to it with each successive element of the enumerable.
The block will be called for each item in the enumerable, with the block's result replacing the current accumulator value.
reduce:
The block to apply, which should accept two parameters: the accumulator and the enumerable value.
mapAcc:
The block to call once to transform the initial accumulator value.
Returns:
The accumulator value obtained after repeatedly applying the block.
reject:
Constructs a new array by retaining elements from this enumerable where a block returns
false
.
map:
The block to use as a condition, which should accept one parameter.
Returns:
The new array.
reverse
Returns an element-wise copy of this enumerable, reversed, as an array. The original is not modified.
Returns:
The reversed array.
skip:
Skips the first n
elements from this enumerable, and takes the rest.
take:
The number of elements to skip.
Returns:
An array of all elements after the first
n
.
skipWhile:
Builds an array with elements from this enumerable, skipping elements from the start until
the predicate function returns false
for the first time.
takeWhile:
The predicate function, which should accept one parameter.
Returns:
The elements taken after the predicate became
false
.
sort
Sorts the elements of this enumerable, from lowest to highest. The elements must implement
Orderable
.
Returns:
A sorted array.
sortBy:
Sorts the elements of this enumerable using the given key function, from lowest key to
highest key. The returned keys must implement Orderable
.
sortBy:
The key function to use, which should accept one parameter.
Returns:
A sorted array.
sum
Adds together the elements in this enumerable, by starting with the integer 0 and repeatedly
calling add:
.
Returns:
The summed value.
take:
Takes the first n
elements from this enumerable.
take:
The number of elements to take.
Returns:
An array of the first
n
elements.
takeWhile:
Builds an array with elements from this enumerable, taking elements from the start until the
predicate function returns false
for the first time.
takeWhile:
The predicate function, which should accept one parameter.
Returns:
The elements taken until the predicate became
false
.
toArray
Converts the contents of this enumerable into an array.
Returns:
The array.
unique
Builds a new array with only unique items, according to equals:
.
If multiple items are equal, the first one in this enumerable is used.
Returns:
An array of unique items.
uniqueBy:
Using the given function to compute keys, builds a new array with only the items with unique
keys, according to equals:
.
If multiple items have unique keys, the first one in this enumerable is used.
s
uniqueBy: The key function, which should take one parameter.
Returns:
An array of the items with unique keys.
window:
Creates a sliding window over the elements in this enumerable of the given size, and builds an array whose elements are arrays of that size.
Each resulting sub-array will overlap with the previous one, except for the elements being "shifted left" by one to push the left-most element off the side and insert a new right-most element.
If the given window size is less than the size of this enumerable, returns an empty array.
window:
The window size to use.
Returns:
An array of arrays of the given size.
withIndex
Constructs a new array composed of new 2-element arrays: the first element is the index of the source item (starting from 0), and the second element is the source item.
Returns:
The new array of 2-element arrays, of the form
#{ index item }
.
zip:
Combines two enumerables into a single array. The elements of the array are themselves two-element arrays, where the first element is from this enumerable and the second element is from the other enumerable.
If either enumerable ends, the overall array ends. This means that the result array will have the length of the shortest of the two enumerables.
zip:
The other enumerable to zip with.
Returns:
An array of two-element arrays from the combined enumerables.
Equatable
Indicates that values of a type can be compared for equality.
This mixin is implemented automatically on all types, and the definition of equals:
is
provided by the interpreter.
Definition: Mixin.
equals:
Determines whether this object is value-equal to another object.
equals:
The other object.
Returns:
true
if the two objects are equal, orfalse
otherwise.
isNull
Whether this object is null
.
Returns:
true
if this object isnull
according toequals:
, orfalse
otherwise.
notEquals:
Determines whether this object is not value-equal to another object.
equals:
The other object.
Returns:
true
if the two objects are not equal, orfalse
otherwise.
File
Represents a handle to an open file on the host machine's filesystem.
Definition: Primitive type.
close
Closes the file. After this, further I/O operations will error.
static
open:
Opens a file for reading.
open:
The path to the file.
Returns:
The opened
File
instance.
static
open:in:
Opens a file, passes it to a block, then closes the file when the block exits.
If the block subverts normal control flow, such as by throwing a value or returning, then the file will not be closed.
open:
The path to the file.
in:
The block to execute, which should take one argument, the path to the file.
Returns:
The result of the block.
readAllText
Reads the file from the current position until the end, returning its contents.
Returns:
The text read from the file.
readByte
Reads one byte from the file, or returns null
if no byte is available.
Returns:
The read byte, or
null
.
readBytes:
Reads a particular number of bytes from the file, or possibly less (including zero) if the file ends or the bytes are not available.
readBytes:
The number of bytes to read.
Returns:
An array of bytes read from the file, no longer than the requested number.
Hashable
Indicates that values of a type can be hashed.
If two values are equal according to Equatable
, then their hash values must also be equal.
(The reverse does not necessarily apply - two values with the same hash may not be equal.)
Note that this is not a cryptographic hash, merely a hash suitable for implementing hash-based data structures such as dictionaries or sets.
This mixin is implemented automatically on all types, and the definition of hash
is
provided by the interpreter.
Definition: Mixin.
hash
A hash value for this object.
Returns:
The hash value, as an integer.
Integer
A whole number.
This type is implemented as a 64-bit signed integer.
Definition: Primitive type.
Uses mixins:
abs
If this integer is negative, returns its absolute value, otherwise returns itself.
Returns:
A positive integer.
add:
Adds the given integer to this one.
add:
The integer to add.
Returns:
The two integers, added.
div:
Performs integer division with another integer.
div:
The divisor.
Returns:
This integer divided by the other integer.
static
fromBigEndianBytes:
Converts an array of big-endian bytes into an integer.
If any of the items of the sequence is outside of the range 0..255, returns null
.
fromBigEndianBytes:
The array of bytes.
Returns:
An integer constructed from these bytes, or
null
if one of the items was invalid.
static
fromLittleEndianBytes:
Converts an array of little-endian bytes into an integer.
If any of the items of the sequence is outside of the range 0..255, returns null
.
fromLittleEndianBytes:
The array of bytes.
Returns:
An integer constructed from these bytes, or
null
if one of the items was invalid.
greaterThan:
Returns true if the given integer is strictly larger than this one.
greaterThan:
The other integer.
Returns:
true
if the other integer is larger than this one, otherwisefalse
.
leftShift:
Shifts this integer left by the specified amount.
leftShift:
The amount to shift by.
Returns:
This integer shifted left by the other integer.
modulo:
Computes the remainder of integer division with a given divisor.
modulo:
The divisor.
Returns:
The remainder of dividing this integer with the divisor.
mul:
Multiplies the given integer with this one.
mul:
The integer to multiply with.
Returns:
The two integers, multiplied.
negate
Flips the sign of this integer.
Returns:
If this integer is positive, the same integer but negative, and vice versa.
rightShift:
Shifts this integer right by the specified amount.
leftShift:
The amount to shift by.
Returns:
This integer shifted right by the other integer.
sub:
Subtracts the given integer from this one.
sub:
The integer to subtract.
Returns:
This integer with the other integer subtracted.
times:
Executes the block the number of times equal to this integer.
times:
The block to execute, which may optionally take a parameter for a counter.
static
zero
The constant integer 0.
Returns:
Match
Encodes the result of a pattern match when calling a ?[ ... ]
block. The match can either be
a hit, where the block was executed and returned the wrapped value, or a miss, where the
pattern did not match.
Definition: Enum with variants:
Hit
, with fields:
value
Miss
static
byThrowing:
Calls a block, which should take one argument. It it throws, returns a miss. If it doesn't, returns a hit with the block's value.
byThrowing:
A one-argument block, taking a tag to throw.
Returns:
A miss if the block throws the tag, or a hit with the block's value if it doesn't.
flatten
Assuming that this match contains another match (if it is a hit), flattens one level of nesting.
For example, Match#Hit value: (Match#Hit value: x))
becomes Match#Hit value: x
. If
either match was a miss, returns a miss.
Returns:
The flattened match, or a miss if this is a miss or the inner value is not a hit.
static
hit:
A shorthand constructor for Match#Hit
.
hit:
The value to use.
Returns:
The new
Match#Hit
instance.
isHit
Whether this match is a hit.
Returns:
true
if this match is a hit, orfalse
otherwise.
isMiss
Whether this match is a miss.
Returns:
true
if this match is a miss, orfalse
otherwise.
map:
If this match is a hit, applies a function to the value and returns a new hit. If it is a miss, returns miss.
map:
The block to execute on the value, taking one parameter.
Returns:
A new hit, or a miss if it was already a miss.
static
mustBeOneOf:
A variant of oneOf:
where the returned block fatally errors if no block matches.
oneOf:
The blocks to compose, each taking one parameter.
Returns:
A new block taking one parameter, which executes each block in turn, and errors if none hit.
static
oneOf:
Composes a new block from an array of other blocks, which will call each block in the array and return the first hit value.
If none of the blocks return a hit, the composed block will return a miss.
oneOf:
The blocks to compose, each taking one parameter.
Returns:
A new block taking one parameter, which executes each block in turn.
value
Undocumented.
static
value:mustBeOneOf:
A shorthand for mustBeOneOf:
which immediately calls the block against the given value.
value:
The value to match against.
oneOf:
The blocks to try matching this against, each taking one parameter.
Returns:
The return value of the first block which returns a hit. Fatally errors if none do.
static
value:toOneOf:
A shorthand for oneOf:
which immediately calls the block against the given value.
value:
The value to match against.
oneOf:
The blocks to try matching this against, each taking one parameter.
Returns:
The return value of the first block which returns a hit, or a miss if none do.
valueOr:
If this match is a hit, returns its value. If it is a miss, returns the given value.
valueOr:
The default value to return if this is a miss.
Returns:
The match's inner value, or the default value.
valueOrElse:
If this match is a hit, returns its value. If it is a miss, executes the given block and returns its return value.
valueOrElse:
The block to execute if this is a miss, taking no parameters.
Returns:
The match's inner value, or the value returned by the block.
static
withExplicitMiss:
Wraps a single-argument pattern block by allowing the block to throw a tag to return an overall miss.
This allows the implementation of 'guard clauses', to be more specific than is possible in a pattern about what should be matched. You can perform arbitrarily-complex checks in the block's body, and pretend that the initial pattern never matched by throwing the tag if necessary.
withExplicitMiss:
A two-argument block, the first being the match subject, and the second being a tag to throw. It should return a match.
Returns:
A new block taking just the match subject, which will return the wrapped block's value, or a miss if the block throws the tag.
MatchProxy
A proxy for pattern matching conveniently against a fixed subject.
This can be generated through the match
method, available on any object through the
Matchable
mixin.
Definition: Struct with fields:
subject
mustBeOneOf:
An alias for Match value:mustBeOneOf:
, against the subject of this proxy.
subject
Field accessor.
Returns:
The value of
subject
.
static
unordered
subject:
Constructor.
Returns:
A new instance of
MatchProxy
.
toOneOf:
An alias for Match value:toOneOf:
, against the subject of this proxy.
Matchable
Provides convenience methods for pattern matching against objects.
This mixin is implemented automatically on all types, and the definition of match
is provided
by the interpreter.
Definition: Mixin.
match
Returns a MatchProxy
with this object as its subject.
The pattern matching methods available on MatchProxy
can then be used to provide an
elegant "pseudo-syntax" for pattern matching
Returns:
A
MatchProxy
for this object.
Null
The type of null
, which represents the absence of a value.
Definition: Primitive type.
Orderable
Indicates that values of a type are orderable.
Requirements:
greaterThan:
Definition: Mixin.
greaterThanOrEquals:
Undocumented.
lessThan:
Undocumented.
lessThanOrEquals:
Undocumented.
Program
A special type containing static methods for interacting with the interpreter itself.
Definition: Primitive type.
static
catchEquals:in:
Runs the given body block, and exits if an object is thrown in it with throw:
and
it equals the given object according to equals:
. If they are not equal, the object is
rethrown.
catchEquals:
The value to compare against.
in:
The block to execute.
Returns:
The value returned by the block, or the thrown value if the block exits early.
static
catchIfTrue:in:
Runs the given body block, and exits if an object is thrown in it with throw:
and
the predicate block returns true
for that thrown object. If the predicate block
returns false
, the object is rethrown.
catchIfTrue:
The predicate.
in:
The body to execute.
Returns:
The value returned by the block, or the thrown value if the block exits early.
static
catchTag:
Runs the given body block, passing it a unique instance of ThrowTag
, and exits if the tag
is thrown with throw:
.
catchTag:
The block to execute, accepting one parameter, the tag.
Returns:
The value returned by the block, or the tag if the block exits early.
static
error:
Exits the interpreter immediately, with a fatal error.
error:
The error message to exit with.
Returns:
This method will never return.
static
eval:
Parses, compiles, and executes a string of Babble code.
As you might guess, this is extremely dangerous to use in combination with any user input. Be careful!
static
evalFile:
Loads a file relative to the file which calls this method, and evaluates its contents in this interpreter.
The same safety warnings as eval:
apply!
static
exit
Exits the interpreter immediately, with a success exit code.
Returns:
This method will never return.
static
filePath
Returns the absolute file path to the file which this method was called from.
Returns:
The absolute file path.
static
filePathBacktrace
An array of absolute file paths, one per stack frame, corresponding to the file from which the code executing in that stack frame was loaded.
The most recent stack frame appears first.
If any stack frame does not have an associated file, that frame's element will be null.
It can still be called like a normal method, but trying to introspect or change this method's definition may not have the intended effect.
Returns:
An array of file paths.
static
loop:
Run the given block repeatedly.
loop:
The block to execute.
Returns:
This method will never return.
static
throw:
Throws an object up the call stack. This can be used to implement complex control flow mechanisms, such as loop breaks.
This must be executed inside a block called by a catch method, such as
catchIfTrue:in:
. (There may be additional blocks or method calls between the throw
and catch.) If the thrown object reaches the top of the call stack and is uncaught,
the interpreter exits with a fatal error.
throw:
The object to throw.
Returns:
This method will never return.
Random
Provides static methods for producing random values.
This uses /dev/random
as a source of randomness, and as such will only work on Unix systems.
Definition: Struct, empty.
static
bytes:
Returns the requested number of random bytes.
bytes:
The number of bytes to return.
Returns:
An array of random bytes.
static
sample:
Returns a random element of the given array.
sample:
The array to sample from.
Returns:
A random element from the array.
static
upTo:
Returns a random integer from 0 up to (but not including) the given limit.
upTo:
The limit.
Returns:
A random integer.
Range
Represents a span of consecutive integers between an inclusive start and exclusive end value.
Definition: Struct with fields:
start
end
Uses mixins:
contains:
Determines whether this range contains an integer, or fully encapsulates another range.
This overrides Enumerable contains:
.
contains:
The integer or range to check.
Returns:
True if this range contains the integer or range, false otherwise.
end
Field accessor.
Returns:
The value of
end
.
forEach:
Calls a function for each integer within the range, passing it as a parameter.
forEach:
The block to call, which should accept one parameter.
start
Field accessor.
Returns:
The value of
start
.
static
unordered
start:end:
Constructor.
Returns:
A new instance of
Range
.
static
upTo:
Constructs a new range with a start of 0 and a given end.
upTo:
The end integer to use.
Returns:
The new range.
Reflection
A special type containing static methods for retrieving metadata information about values or types.
Definition: Primitive type.
static
instanceType:
If the given object is a value, returns its type. If the given object is already a type, returns that type.
The
object.
Returns:
The object's type, or itself if it was already a type.
static
isType:
Determines whether an object is itself a type.
isType:
The object to check.
Returns:
True if it is a type, or false otherwise.
static
type:
Gets the type of an object.
type:
The object whose type to fetch.
Returns:
The object's type.
static
variant:
Gets the name of the variant of an enum instance.
variant:
The enum instance.
Returns:
The variant's name as a string, or
null
if it is not an enum variant.
Representable
Indicates that a type can be converted to a string.
This mixin is implemented automatically on all types, and the definition of repr
is
provided by the interpreter.
Definition: Mixin.
repr
A debug string representation of this value.
Returns:
The string representation.
String
A string of UTF-8 characters.
Definition: Primitive type.
charAt:
Gets a single character from this string.
charAt:
The index of the character to get.
Returns:
A substring of a single character, or
null
if the index is out of bounds.
static
charFromAsciiCode:
Constructs a new single-character string from an ASCII character code.
charsFromAsciiCode:
The character code as an integer.
Returns:
A single-character string, or
null
if the code is out of bounds.
chars
Gets the characters within this string.
Returns:
An array of this string's characters.
concat:
Appends another string to this one, and returns the concatenated string.
concat:
The other string.
Returns:
A new string, with the given string appearing after this one.
static
interpolate:
Given an array of values implementing Representable
, converts each to a string and then
joins the values together.
Used to implement string interpolation syntax.
parts:
The parts to interpolate.
Returns:
The interpolated string.
isWhitespace
Whether this string is composed entirely of whitespace.
This currently only supports ASCII whitespace characters: \r, \n, \t, and space.
Returns:
true
if the string is entirely ASCII whitespace,false
otherwise.
length
The length of this string.
Returns:
The number of characters in this string.
lowercase
Returns a copy of this string, with all letters converted to lowercase.
Returns:
The new lowercase string.
replace:with:
Replaces occurrences of one character with another.
replace:
The character to replace.
with:
The character to replace it with.
Returns:
A new string with the character replaced wherever it appears.
split:
Splits a string using another string as a separator.
split:
The separator to split on.
Returns:
An array of separated strings.
strip
Returns a copy of this string with whitespace stripped from the beginning and end.
Returns:
The new string with whitespace stripped.
toAsciiCode
Converts a string with a single character to that character's ASCII code. If the
string is not a single character, or the character is not ASCII, returns null
.
Returns:
The character's ASCII code, or
null
.
toInteger
Parses this string as a base-10 integer. If the string is not a valid integer, returns null
.
Returns:
An integer, or
null
.
toInteger:
Parses this string as an integer of the given base. If the string is not a valid integer, returns null
.
If the base is outside of the range 2..36 inclusive, raises an error.
s
toInteger: The base to parse the integer in.
Returns:
An integer, or
null
.
uppercase
Returns a copy of this string, with all letters converted to uppercase.
Returns:
The new uppercase string.
ThrowTag
A globally-unique value created exclusively by the catchTag:
method on Program
, to ensure
that a thrown value will always be caught by one exact known catch block.
Instances of this struct should not be created manually.
Definition: Struct with fields:
id
static next
id
Field accessor.
Returns:
The value of
id
.
static
unordered
id:
Constructor.
Returns:
A new instance of
ThrowTag
.
static
new
Undocumented.
static
next
Static field accessor.
Returns:
The value of
next
.