Tables
Tables are the only compound data structure available in Quarrel. They are associative arrays which, in Quarrel, means they store a collection of containers which can be looked up by means of the two available syntaxes: \
tight infix operator and the [...]
postcircumfix operator. Additionally, one can enter the context of a table by supplying a table container to a ->
operator (the applicand now has access to the internal contextual containers (keys)).
#
How to...#
create a tableTables are constructed using the []
circumfix operator.
Values can be added to the table literal, separated by ,
operators.
Without container names for these literals, they are stored in the default positional containers 1, 2, 3, etc.
To supply a contextual container names, use the .
and :
postfix operators
#
convert to a#
get a list of all of the named elements#
OperatorsBinary and unary operations that act specifically on Tables.
<:
Appends a table to anther table (order matters)
#
Examples>:
#
To append but explode the outermost list element into the enclosing context (order matters)
#
Examples#
Method OperatorsMany common ways to interact with lists are implemented by syntax within the postcircumfix square brackets. You can get the index of a value by using ?
as your index to get a check routine It returns either the index number or an empty sequence.
Add a new list items to the end by using the [+]
postcirmfux method operator.
Remove list items with !
, takes one argument: the index to remove.
First and last elements:
To take the first or list while removing from the original list, use the <!
or !>
operators.
Specify how many to shift or pop by placing a number next to the colon
To get a length of a list, use a @ inside brackets:
To delete elements of a list, use [!]
and provide the position to delete as a routine argument:
To set a value to empty, assign it ()!
:
-
#
Resolves to all of the elements of the x
Table that aren't in the y
Table. Uses a ==
comparison between each element of the two tables.
#
Examples|
#
Resolves to a union of all the elements of the x
Table plus any unique elements of the y
Table that aren't in the x
Table.
#
Examples&
#
Resolves to only the elements of the x
and y
Tables that are in both Tables.
#
Examples==
#
Resolves to true
if the left Table's potional values are the same as the right Table's positional values
#
Examples<>
#
Resolves to true
if the left Table potional values are not the same as the right Table's positional values
#
Examples===
#
Resolves to true
if the left Table has the exact same positional and key-based values as the right Table
#
Examples>>
#
Resolves to true
if the left Table positional values are a strict superset of the right Table's positional values
#
Examples<<
#
Resolves to true
if the left Table's positional values are a strict subset of the right Table's positional values
>=
#
Resolves to true
if the left Table's positional values are a superset of or equal to the right Table's positional values
#
Examples<=
#
Resolves to true
if the left Table's positional valus are a subset of or equal to the right Table's positional values.
#
Examples***
#
Picks a number of random elements from the table. If the integer is greater than 1, returns a table of picked elements instead of just one.
#
Examples#
Method OperatorsMethod operations that are performed on Table containers.
[x]
#
Lookup the value corresponding to the key x
#
Examples[+]
#
Add a value to a table at the next available numerical position
#
Examples[@]
#
Return the length of the table
#
Examples[\]
#
Check if the table contains a certain key
#
Examples[/]
#
Check if the table contains a certain value, returning the location or ()
#
Examples[!]
#
Delete a value in a table with a key