Boolean
Functions that work with true and false values.
true
Returns a boolean true value.
none
returns boolean true value
true
; returns true
true |type?
; returns boolean
false
Returns a boolean false value.
none
returns boolean false value
false
; returns false
false |type?
; returns boolean
not
Performs logical negation on boolean values only.
value Boolean value to be negated
returns boolean false if the input is true, true if the input is false
not true
; returns false
not false
; returns true
not 0
; correctly causes error:
; builtin `not` requires argument 1 to be: Boolean.
not 5
; correctly causes error:
; builtin `not` requires argument 1 to be: Boolean.
and
Performs a logical AND operation between two boolean values, or a bitwise AND operation between two integer values.
value1 First value (boolean or integer)
value2 Second value (boolean or integer)
returns boolean result of logical AND operation if both inputs are booleans, otherwise integer result of bitwise AND
true .and true
; returns true
false .and true
; returns false
true .and false
; returns false
false .and false
; returns false
3 .and 5
; returns 1
true .and 5
; correctly causes error:
; builtin `and` requires argument 2 to be: Boolean.
5 .and true
; correctly causes error:
; builtin `and` requires argument 2 to be: Integer.
"string" .and true
; correctly causes error:
; builtin `and` requires argument 1 to be: Boolean, Integer.
or
Performs a logical OR operation between two boolean values, or a bitwise OR operation between two integer values.
value1 First value (boolean or integer)
value2 Second value (boolean or integer)
returns boolean result of logical OR operation if both inputs are booleans, otherwise integer result of bitwise OR
true .or true
; returns true
false .or true
; returns true
true .or false
; returns true
false .or false
; returns false
3 .or 5
; returns 7
true .or 5
; correctly causes error:
; builtin `or` requires argument 2 to be: Boolean.
5 .or true
; correctly causes error:
; builtin `or` requires argument 2 to be: Integer.
"string" .or true
; correctly causes error:
; builtin `or` requires argument 1 to be: Boolean, Integer.
xor
Performs a logical XOR (exclusive OR) operation between two boolean values, or a bitwise XOR operation between two integer values.
value1 First value (boolean or integer)
value2 Second value (boolean or integer)
returns boolean result of logical XOR operation if both inputs are booleans, otherwise integer result of bitwise XOR
true .xor true
; returns false
false .xor true
; returns true
true .xor false
; returns true
false .xor false
; returns false
3 .xor 5
; returns 6
true .xor 5
; correctly causes error:
; builtin `xor` requires argument 2 to be: Boolean.
5 .xor true
; correctly causes error:
; builtin `xor` requires argument 2 to be: Integer.
"string" .xor true
; correctly causes error:
; builtin `xor` requires argument 1 to be: Boolean, Integer.
all
Evaluates all expressions in a block and returns the last value if all are truthy, or the first falsy value encountered.
block Block of expressions to evaluate
returns the last value if all expressions are truthy, otherwise the first falsy value encountered
all { 1 2 3 }
; returns 3
all { 1 0 3 }
; returns 3
all { 1 false 3 }
; returns false
all { true true true }
; returns true
all "not-a-block"
; correctly causes error:
; builtin `all` requires argument 1 to be: Block.
any
Evaluates expressions in a block until a truthy value is found and returns it, or returns the last value if none are truthy.
block Block of expressions to evaluate
returns the first truthy value encountered, or the last value if none are truthy
any { 1 2 3 }
; returns 1
any { 0 1 3 }
; returns 0
any { false false 3 }
; returns 3
any { false false false }
; returns false
any "not-a-block"
; correctly causes error:
; builtin `any` requires argument 1 to be: Block.
any\with
Applies each expression in the block to the provided value until a truthy result is found and returns it.
value Value to be used as input to each expression in the block
block Block of expressions to evaluate with the provided value injected
returns the first truthy result of applying an expression to the value, or the last result if none are truthy
any\with 10 { + 10 , * 10 }
; returns 20
any\with 0 { + 10 , * 10 }
; returns 10
any\with 5 { - 10 , + 10 }
; returns -5
any\with false { .not , .to-string }
; returns true
any\with 5 "not-a-block"
; correctly causes error:
; builtin `any\with` requires argument 2 to be: Block.
Numbers
Working with numbers, integers and decimals.
inc
Increments an integer value by 1.
value Integer to increment
returns integer value incremented by 1
inc 123
; returns 124
inc 0
; returns 1
inc -5
; returns -4
inc "123"
; correctly causes error:
; builtin `inc` requires argument 1 to be: Integer.
decr
Decrements an integer value by 1.
value Integer to decrement
returns integer value decremented by 1
decr 124
; returns 123
decr 1
; returns 0
decr -4
; returns -5
decr "123"
; correctly causes error:
; builtin `decr` requires argument 1 to be: Integer.
is-positive
Checks if a number is positive (greater than zero).
value Integer or decimal to check
returns boolean true if the value is positive, false otherwise
is-positive 123
; returns true
is-positive -123
; returns false
is-positive 0
; returns false
is-positive 5.5
; returns true
is-positive "123"
; correctly causes error:
; builtin `is-positive` requires argument 1 to be: Integer, Decimal.
is-zero
Checks if a number is exactly zero.
value Integer or decimal to check
returns boolean true if the value is zero, false otherwise
is-zero 0
; returns true
is-zero 123
; returns false
is-zero 0
; returns true
is-zero "123"
; correctly causes error:
; builtin `is-zero` requires argument 1 to be: Integer, Decimal.
is-multiple-of
Checks if the first integer is evenly divisible by the second integer.
value Integer to check
divisor Integer divisor to check against
returns boolean true if value is divisible by divisor with no remainder, false otherwise
10 .is-multiple-of 2
; returns true
10 .is-multiple-of 3
; returns false
15 .is-multiple-of 5
; returns true
0 .is-multiple-of 5
; returns true
is-odd
Checks if an integer is odd (not divisible by 2).
value Integer to check
returns boolean true if the value is odd, false if even
3 .is-odd
; returns true
2 .is-odd
; returns false
0 .is-odd
; returns false
-5 .is-odd
; returns true
is-even
Checks if an integer is even (divisible by 2).
value Integer to check
returns boolean true if the value is even, false if odd
3 .is-even
; returns false
2 .is-even
; returns true
0 .is-even
; returns true
-4 .is-even
; returns true
mod
Calculates the modulo (remainder) when dividing the first integer by the second.
value Integer dividend
divisor Integer divisor
returns integer remainder after division
4 .mod 2
; returns 0
5 .mod 2
; returns 1
5 .mod 3
; returns 2
-5 .mod 3
; returns -2
_%
Alias for mod - calculates the modulo (remainder) when dividing the first integer by the second.
value Integer dividend
divisor Integer divisor
returns integer remainder after division
4 % 2
; returns 0
5 % 2
; returns 1
5 % 3
; returns 2
random\integer
Generates a cryptographically secure random integer between 0 (inclusive) and the specified maximum (exclusive).
max Upper bound (exclusive) for the random number
returns random integer in the range [0, max)
random\integer 2 |type?
; returns integer
random\integer 1 |< 2
; returns true
random\integer 100 || >= 0
; returns true
random\decimal
Generates a cryptographically secure random decimal between 0.0 (inclusive) and the specified maximum (exclusive).
max Upper bound (exclusive) for the random number
returns random decimal in the range [0.0, max)
random\decimal 2 |type?
; returns decimal
random\decimal 1 |< 1
; returns true
random\decimal 100 || >= 0
; returns true
inc!
Increments an integer value stored in a variable (word) by 1 and updates the variable in-place.
word Word referring to an integer value to increment
returns the new incremented integer value
a:: 123 inc! 'a a
; returns 124
counter:: 0 inc! 'counter counter
; returns 1
inc! 123
; correctly causes error:
; builtin `inc!` requires argument 1 to be: Word.
decr!
Decrements an integer value stored in a variable (word) by 1 and updates the variable in-place.
word Word referring to an integer value to decrement
returns the new decremented integer value
a:: 123 decr! 'a a
; returns 122
counter:: 1 decr! 'counter counter
; returns 0
decr! 123
; correctly causes error:
; builtin `decr!` requires argument 1 to be: Word.
_.
Discards the input value and returns a void value, useful for ignoring unwanted results in a pipeline.
value Any value to discard
returns void value (used to discard values)
4 . .type?
; returns void
"hello" . .type?
; returns void
_+
Adds or joins two values together, with behavior depending on types: adds numbers, concatenates strings/blocks, merges dictionaries, etc.
value1 First value (number, string, block, dict, etc.)
value2 Second value to add or join
returns result of adding or joining the values, type depends on input types
1 + 1
; returns 2
3 + 4
; returns 7
5.6 + 7.8
; returns 13.399999999999999
"A" + "b"
; correctly causes error:
; builtin `_+` requires argument 1 to be: Integer, Decimal, Complex, Time.
"A" + 1
; correctly causes error:
; builtin `_+` requires argument 1 to be: Integer, Decimal, Complex, Time.
{ 1 2 } + { 3 4 }
; correctly causes error:
; builtin `_+` requires argument 1 to be: Integer, Decimal, Complex, Time.
dict { "a" 1 } |+ { "b" 2 }
; correctly causes error:
; builtin `_+` requires argument 1 to be: Integer, Decimal, Complex, Time.
dict { "a" 1 } |+ dict { "b" 2 }
; correctly causes error:
; builtin `_+` requires argument 1 to be: Integer, Decimal, Complex, Time.
_-
Subtracts the second number from the first, working with integers, decimals, and complex numbers.
value1 First number (integer or decimal)
value2 Second number to subtract from the first
returns result of subtracting value2 from value1
2 - 1
; returns 1
5 - 6
; returns -1
5.5 - 2.2
; returns 3.3
5 - 2.5
; returns 2.5
_*
Multiplies two numbers, working with integers, decimals, and complex numbers.
value1 First number (integer or decimal)
value2 Second number to multiply by
returns product of the two numbers
4 * 2
; returns 8
2.5 * -2
; returns -5
0 * 5
; returns 0
1.5 * 2.5
; returns 3.75
_/
Divides the first number by the second and returns a result, with error checking for division by zero.
value1 Dividend (integer or decimal)
value2 Divisor (integer or decimal, must not be zero)
returns decimal result of dividing value1 by value2
4 / 2
; returns 2
102 / 2
; returns 51
5 / 2
; returns 2.5
5 / 0
; correctly causes error:
; Can't divide by Zero. in builtin _/.
_//
Performs integer division, dividing the first number by the second and truncating to an integer result.
value1 Dividend (integer or decimal)
value2 Divisor (integer or decimal, must not be zero)
returns integer result of dividing value1 by value2 (truncated)
5 // 2
; returns 2
102 // 5
; returns 20
7.99 // 2
; returns 3
-5 // 2
; returns -2
5 // 0
; correctly causes error:
; Can't divide by Zero. in builtin _//.
_=
Compares two values for equality, returning 1 if equal or 0 if not equal.
value1 First value to compare
value2 Second value to compare
returns boolean true if values are equal, false otherwise
5 = 5
; returns true
5 = 4
; returns false
"abc" = "abc"
; returns true
{ 1 2 } = { 1 2 }
; returns true
{ 1 2 } = { 2 1 }
; returns false
_>
Compares if the first value is greater than the second value.
value1 First value to compare
value2 Second value to compare
returns boolean true if value1 is greater than value2, false otherwise
6 > 5
; returns true
5 > 5
; returns false
4 > 5
; returns false
5.5 > 5
; returns true
"b" > "a"
; returns true
_>=
Compares if the first value is greater than or equal to the second value.
value1 First value to compare
value2 Second value to compare
returns boolean true if value1 is greater than or equal to value2, false otherwise
5 >= 6
; returns false
5 >= 5
; returns true
6 >= 5
; returns true
4 >= 5
; returns false
"b" >= "a"
; returns true
"a" >= "a"
; returns true
_<
Compares if the first value is less than the second value.
value1 First value to compare
value2 Second value to compare
returns boolean true if value1 is less than value2, false otherwise
5 < 6
; returns true
5 < 5
; returns false
6 < 5
; returns false
4.5 < 5
; returns true
"a" < "b"
; returns true
_<=
Compares if the first value is less than or equal to the second value.
value1 First value to compare
value2 Second value to compare
returns boolean true if value1 is less than or equal to value2, false otherwise
5 <= 6
; returns true
5 <= 5
; returns true
6 <= 5
; returns false
4.5 <= 5
; returns true
"a" <= "b"
; returns true
"a" <= "a"
; returns true
recur-if
Internal recursion control function. Resets function execution if condition > 0, otherwise returns result.
condition Integer value, if > 0 triggers recursion reset
returns nil if recursion continues, ps.Res if recursion ends
recur-if\1
Internal recursion control function for single-argument functions. Updates first argument and resets if condition > 0.
condition Integer value, if > 0 triggers recursion with updated argument
arg1 New value for the first function argument during recursion
returns nil if recursion continues, ps.Res if recursion ends
recur-if\2
Internal recursion control function for two-argument functions. Updates both arguments and resets if condition > 0.
condition Integer value, if > 0 triggers recursion with updated arguments
arg1 New value for the first function argument during recursion
arg2 New value for the second function argument during recursion
returns ps.Res (function result) regardless of condition
recur-if\3
Internal recursion control function for three-argument functions. Updates all three arguments and resets if condition > 0.
condition Integer value, if > 0 triggers recursion with updated arguments
arg1 New value for the first function argument during recursion
arg2 New value for the second function argument during recursion
arg3 New value for the third function argument during recursion
returns ps.Res (function result) regardless of condition, nil if recursion continues
Strings
newline
Returns a string containing a single newline character.
none
returns a string containing a single newline character
newline
; returns "
; "
tab
Returns a string containing a single tab character.
none
returns a string containing a single tab character
tab
; returns " "
ln
Appends a newline character to the end of a string.
string String to append a newline to
returns a new string with a newline character appended
"123" .ln
; returns "123
; "
"hello" .ln
; returns "hello
; "
trim
Removes all leading and trailing whitespace characters from a string.
string String to trim
returns a new string with leading and trailing whitespace removed
trim " ASDF "
; returns "ASDF"
trim " ASDF "
; returns "ASDF"
trim "
ASDF
"
; returns "ASDF"
trim\
Removes all leading and trailing occurrences of the specified characters from a string.
string String to trim
cutset String containing the characters to trim
returns a new string with specified characters removed from both ends
trim\ "__ASDF__" "_"
; returns "ASDF"
trim\ "##Hello##" "#"
; returns "Hello"
trim\ ight
Removes all trailing occurrences of the specified characters from a string.
string String to trim
cutset String containing the characters to trim
returns a new string with specified characters removed from the right end
trim\right "__ASDF__" "_"
; returns "__ASDF"
trim\right " ASDF " " "
; returns " ASDF"
trim\right "Hello!!!" "!"
; returns "Hello"
trim\left
Removes all leading occurrences of the specified characters from a string.
string String to trim
cutset String containing the characters to trim
returns a new string with specified characters removed from the left end
trim\left "___ASDF__" "_"
; returns "ASDF__"
trim\left " ASDF " " "
; returns "ASDF "
trim\left "###Hello" "#"
; returns "Hello"
replace
Replaces all occurrences of a substring with another string.
string Original string
old Substring to replace
new Replacement string
returns a new string with all occurrences of old replaced by new
replace "...xo..." "xo" "LoL"
; returns "...LoL..."
replace "...xoxo..." "xo" "LoL"
; returns "...LoLLoL..."
replace "hello world" "world" "everyone"
; returns "hello everyone"
substring
Extracts a portion of a string between the specified start and end positions.
string String to extract from
start Starting position (0-based, inclusive)
end Ending position (0-based, exclusive)
returns a new string containing the specified substring
substring "xoxo..." 0 4
; returns "xoxo"
substring "...xoxo..." 3 7
; returns "xoxo"
substring "hello world" 6 11
; returns "world"
contains
Checks if a string, block or list contains a specific value, returning 1 if found or 0 if not found.
collection String, block or list to search in
value Value to search for
returns integer 1 if the collection contains the value, 0 otherwise
contains "...xoxo..." "xo"
; returns true
contains "...xoxo..." "lol"
; returns false
contains { ".." "xoxo" ".." } "xoxo"
; returns true
contains { ".." "xoxo" ".." } "lol"
; returns false
contains list { 1 2 3 } 2
; returns true
has-suffix
Checks if a string ends with a specific suffix, returning 1 if true or 0 if false.
string String to check
suffix Suffix to look for
returns integer 1 if the string ends with the suffix, 0 otherwise
has-suffix "xoxo..." "xoxo"
; returns 0
has-suffix "...xoxo" "xoxo"
; returns 1
has-suffix "hello.txt" ".txt"
; returns 1
has-prefix
Checks if a string starts with a specific prefix, returning 1 if true or 0 if false.
string String to check
prefix Prefix to look for
returns integer 1 if the string starts with the prefix, 0 otherwise
has-prefix "xoxo..." "xoxo"
; returns 1
has-prefix "...xoxo" "xoxo"
; returns 0
has-prefix "http://example.com" "http://"
; returns 1
index?
Finds the 0-based index of the first occurrence of a value in a string or block.
collection String or block to search in
value Value to search for
returns integer index (0-based) of the first occurrence of the value, or -1 if not found
index? "...xo..." "xo"
; returns 3
index? "xo..." "xo"
; returns 0
index? { "xo" ".." } "xo"
; returns 0
index? { ".." "xo" ".." } "xo"
; returns 1
position?
Finds the 1-based position of the first occurrence of a value in a string or block.
collection String or block to search in
value Value to search for
returns integer position (1-based) of the first occurrence of the value, or error if not found
position? "...xo..." "xo"
; returns 4
position? "xo..." "xo"
; returns 1
position? { "xo" ".." } "xo"
; returns 1
position? { ".." "xo" ".." } "xo"
; returns 2
encode-to\base64
Encodes a string or binary data as a base64 string.
data String or native bytes/pem-block to encode
returns base64-encoded string
encode-to\base64 "abcd"
; returns "YWJjZA=="
encode-to\base64 "hello world"
; returns "aGVsbG8gd29ybGQ="
decode\base64
Decodes a base64-encoded string back to its original form.
string Base64-encoded string to decode
returns decoded string
decode\base64 encode-to\base64 "abcd"
; returns "abcd"
decode\base64 "aGVsbG8gd29ybGQ="
; returns "hello world"
space
Appends a space character to the end of a string.
string String to append a space to
returns a new string with a space character appended
"abcd" .space
; returns "abcd "
"" .space
; returns " "
capitalize
Converts the first character of a string to uppercase, leaving the rest unchanged.
string String to capitalize
returns a new string with the first character converted to uppercase
capitalize "abcde"
; returns "Abcde"
capitalize "hello world"
; returns "Hello World"
capitalize "HELLO"
; returns "Hello"
to-lower
Converts all characters in a string to lowercase.
string String to convert
returns a new string with all characters converted to lowercase
to-lower "ABCDE"
; returns "abcde"
to-lower "Hello World"
; returns "hello world"
to-lower "123ABC"
; returns "123abc"
to-upper
Converts all characters in a string to uppercase.
string String to convert
returns a new string with all characters converted to uppercase
to-upper "abcde"
; returns "ABCDE"
to-upper "Hello World"
; returns "HELLO WORLD"
to-upper "123abc"
; returns "123ABC"
concat3
Concatenates three strings together into a single string.
string1 First string
string2 Second string
string3 Third string
returns a new string containing all three strings concatenated together
concat3 "aa" "BB" "cc"
; returns "aaBBcc"
concat3 "hello" " " "world"
; returns "hello world"
join
Concatenates all strings or numbers in a block or list into a single string with no separator.
collection Block or list of strings or numbers to join
returns a single string with all values concatenated together
join { "Mary" "Anne" }
; returns "MaryAnne"
join { "Spot" "Fido" "Rex" }
; returns "SpotFidoRex"
join { 1 2 3 }
; returns "123"
join\with
Concatenates all strings or numbers in a block or list into a single string with a specified delimiter between values.
collection Block or list of strings or numbers to join
delimiter String to insert between each value
returns a single string with all values concatenated with the delimiter between them
join\with { "Mary" "Anne" } " "
; returns "Mary Anne"
join\with { "Spot" "Fido" "Rex" } "/"
; returns "Spot/Fido/Rex"
join\with { 1 2 3 } "-"
; returns "1-2-3"
split
Splits a string into a block of strings using a separator string.
string String to split
separator String that separates values
returns a block of strings resulting from splitting the input string
split "a,b,c" ","
; returns { "a" "b" "c" }
split "hello world" " "
; returns { "hello" "world" }
split "one::two::three" "::"
; returns { "one" "two" "three" }
split\quoted
Splits a string into a block of strings using a separator, while respecting quoted sections that should remain intact.
string String to split
separator String that separates values
quote String that marks quoted sections that should not be split
returns a block of strings resulting from splitting the input string, preserving quoted sections
split\quoted "`a,b`,c,d" "," "`"
; returns { "`a,b`" "c" "d" }
split\quoted "'hello, world',foo,bar" "," "'"
; returns { "'hello, world'" "foo" "bar" }
split\many
Splits a string into a block of strings using any character in the separators string as a delimiter.
string String to split
separators String containing all characters that should be treated as separators
returns a block of strings resulting from splitting the input string at any of the separator characters
split\many "192.0.0.1" "."
; returns { "192" "0" "0" "1" }
split\many "abcd..e.q|bar" ".|"
; returns { "abcd" "e" "q" "bar" }
split\many "a;b,c:d" ";,:"
; returns { "a" "b" "c" "d" }
split\every
Splits a string or block into chunks of the specified size, with any remaining elements in the last chunk.
collection String or block to split
size Number of elements in each chunk
returns a block of strings or blocks, each containing at most 'size' elements
split\every "abcdefg" 3
; returns { "abc" "def" "g" }
split\every "abcdefg" 2
; returns { "ab" "cd" "ef" "g" }
split\every "abcdef" 2
; returns { "ab" "cd" "ef" }
split\every { 1 2 3 4 5 } 2
; returns { { 1 2 } { 3 4 } { 5 } }
Collections
random
Selects a random value from a block of values.
block Block of values to select from
returns a randomly selected value from the block
random { 1 2 3 } |type?
; returns integer
random { 1 2 3 } |contains* { 1 2 3 }
; returns true
unpack
Flattens a block of blocks or list of lists by one level, combining all inner collections into a single collection.
collection Block or list of blocks/lists to unpack
returns a flattened block or list with all inner blocks/lists unpacked
unpack { { 123 } { 234 } }
; returns { 123 234 }
unpack { { { 123 } } { 234 } }
; returns { { 123 } 234 }
sample
Randomly selects a specified number of elements from a collection without replacement.
collection Block, list or table to sample from
count Number of random elements to select
returns a new collection with randomly selected elements
sample { 1 2 3 4 } 2 |length?
; returns 2
sample { 123 123 123 123 } 3 |-> 0
; returns 123
max
Finds the maximum value in a block or list of comparable values.
collection Block or list of comparable values
returns the maximum value in the collection
max { 8 2 10 6 }
; returns 10
max list { 8 2 10 6 }
; returns 10
try { max { } } |type?
; returns error
try { max list { } } |type?
; returns error
min
Finds the minimum value in a block or list of comparable values.
collection Block or list of comparable values
returns the minimum value in the collection
min { 8 2 10 6 }
; returns 2
min list { 8 2 10 6 }
; returns 2
try { min { } } |type?
; returns error
try { min list { } } |type?
; returns error
avg
Calculates the arithmetic mean (average) of numeric values in a collection.
collection Block, list or vector of numeric values
returns the arithmetic mean (average) of the values as a decimal
avg { 8 2 10 6 }
; returns 6.5
avg list { 8 2 10 6 }
; returns 6.5
avg { 1 2 3 }
; returns 2
try { avg { } } |type?
; returns error
try { avg list { } } |type?
; returns error
sum
Calculates the sum of all numeric values in a collection.
collection Block, list or vector of numeric values
returns the sum of all values (integer if all values are integers, decimal otherwise)
sum { 8 2 10 6 }
; returns 26
sum { 8 2 10 6.5 }
; returns 26.5
sum { }
; returns 0
sum list { 8 2 10 6 }
; returns 26
sum list { 8 2 10 6.5 }
; returns 26.5
sum list { }
; returns 0
mul
Calculates the product of all numeric values in a collection.
collection Block, list or vector of numeric values
returns the product of all values (integer if all values are integers, decimal otherwise)
mul { 1 2 3 4 5 }
; returns 120
mul { 1 2 3.3 4 5 }
; returns 132
mul { 2 3 4 }
; returns 24
first
Retrieves the first item from a collection (block, list, string, or table).
collection Block, list, string or table to get the first item from
returns the first item in the collection
first { 1 2 3 4 }
; returns 1
first "abcde"
; returns "a"
first list { 1 2 3 }
; returns 1
rest
Creates a new collection with all items except the first one from the input collection.
collection Block, list or string to get all but the first item from
returns a new collection containing all items except the first one
rest { 1 2 3 4 }
; returns { 2 3 4 }
rest "abcde"
; returns "bcde"
rest list { 1 2 3 }
; returns list { 2 3 }
rest { 1 }
; returns { }
rest\from
Creates a new collection with all items starting from the specified position in the input collection.
collection Block, list or string to get items from
n Integer position to start from (0-based)
returns a new collection containing all items starting from position n
rest\from { 1 2 3 4 5 6 } 3
; returns { 4 5 6 }
rest\from "abcdefg" 1
; returns "bcdefg"
rest\from list { 1 2 3 4 } 2
; returns list { 3 4 }
rest\from { 1 2 3 } 0
; returns { 1 2 3 }
tail
Creates a new collection with the last n items from the input collection.
collection Block, list, string or table to get the last items from
n Number of items to retrieve from the end
returns a new collection containing the last n items
tail { 1 2 3 4 5 6 7 } 3
; returns { 5 6 7 }
tail "abcdefg" 4
; returns "defg"
tail list { 1 2 3 4 } 1
; returns list { 4 }
tail { 1 2 } 5
; returns { 1 2 }
second
Retrieves the second item from a collection (block, list, or string).
collection Block, list or string to get the second item from
returns the second item in the collection
second { 123 234 345 }
; returns 234
second "abc"
; returns "b"
second list { 10 20 30 }
; returns 20
third
Retrieves the third item from a collection (block, list, or string).
collection Block, list or string to get the third item from
returns the third item in the collection
third { 123 234 345 }
; returns 345
third "abcde"
; returns "c"
third list { 10 20 30 40 }
; returns 30
last
Retrieves the last item from a collection (block, list, or string).
collection Block, list or string to get the last item from
returns the last item in the collection
last { 1 2 }
; returns 2
last "abcd"
; returns "d"
last list { 4 5 6 }
; returns 6
try { last { } } |type?
; returns error
head
Creates a new collection with the first n items from the input collection, or all but the last |n| items if n is negative.
collection Block, list, string or table to get the first items from
n Number of items to retrieve (if positive) or number to exclude from the end (if negative)
returns a new collection containing the first n items or all but the last |n| items
head { 4 5 6 7 } 3
; returns { 4 5 6 }
head "abcdefg" 2
; returns "ab"
head "abcdefg" 4
; returns "abcd"
head list { 10 20 30 40 } 2
; returns list { 10 20 }
head { 4 5 6 7 } -2
; returns { 4 5 }
head "abcdefg" -1
; returns "abcdef"
head "abcdefg" -5
; returns "ab"
head list { 10 20 30 40 } -1
; returns list { 10 20 30 }
nth
Retrieves the item at the specified position (1-based indexing) from a collection.
collection Block, list, string or table to get an item from
n Position of the item to retrieve (1-based)
returns the item at position n in the collection
nth { 1 2 3 4 5 } 4
; returns 4
nth { "a" "b" "c" "d" "e" } 2
; returns "b"
nth "abcde" 3
; returns "c"
nth list { 10 20 30 40 } 2
; returns 20
values
Extracts all values from a dictionary and returns them as a list.
dict Dictionary object to extract values from
returns list containing all values from the dictionary
dict { "a" 1 "b" 2 "c" 3 } |values
; returns list { 1 2 3 }
dict { "x" 10 "y" 20 } |values |length?
; returns 2
sort
Creates a new collection with items sorted in ascending order.
collection Block, list or string to sort
returns a new collection with items sorted in ascending order
sort { 6 12 1 }
; returns { 1 6 12 }
sort x: { 6 12 1 } x
; returns { 6 12 1 }
sort { "b" "c" "a" }
; returns { "a" "b" "c" }
sort list { 5 3 1 4 }
; returns list { 1 3 4 5 }
sort "cba"
; returns "abc"
sort!
Sorts a block or list in-place in ascending order and returns the modified collection.
collection Reference to a block or list to sort in-place
returns the sorted collection (same reference, modified in-place)
x: { 6 12 1 } , sort! x
; correctly causes error:
; builtin `sort!` requires argument 1 to be: Block, List.
x: ref { 1 6 12 } , sort! x , x
; returns { 1 6 12 }
x: ref list { 5 3 1 4 } , sort! x , x
; returns list { 1 3 4 5 }
sort\by
Creates a new collection with items sorted according to a custom comparison function.
collection Block or list to sort
comparator Function that takes two arguments and returns a truthy value if they are in the correct order
returns a new collection with items sorted according to the comparator function
sort\by { 6 12 1 } fn { a b } { a < b }
; returns { 1 6 12 }
sort\by { 6 12 1 } fn { a b } { a > b }
; returns { 12 6 1 }
sort\by { { x 6 } { x 12 } { x 1 } } fn { a b } { second a |< second b }
; returns { { x 1 } { x 6 } { x 12 } }
sort\by list { 5 3 1 4 } fn { a b } { a > b }
; returns list { 5 4 3 1 }
unique
Creates a new collection with duplicate values removed, keeping only the first occurrence of each value.
collection Block, list or string to remove duplicates from
returns a new collection with duplicate values removed
list { 3 2 3 5 3 2 } .unique |sort
; returns list { 2 3 5 }
unique list { 1 1 2 2 3 } |sort
; returns list { 1 2 3 }
unique list { 1 1 2 2 } |sort
; returns list { 1 2 }
unique { 1 1 2 2 3 } |sort
; returns { 1 2 3 }
unique { 1 1 2 2 } |sort
; returns { 1 2 }
reverse
Creates a new collection with items in reverse order from the input collection.
collection Block, list or string to reverse
returns a new collection with items in reverse order
reverse { 3 1 2 3 }
; returns { 3 2 1 3 }
reverse "abcd"
; returns "dcba"
reverse list { 1 2 3 4 }
; returns list { 4 3 2 1 }
reverse { }
; returns { }
reverse!
Reverses a block or list in-place and returns the modified collection.
collection Reference to a block or list to reverse in-place
returns the reversed collection (same reference, modified in-place)
reverse! { 3 1 2 3 }
; correctly causes error:
; builtin `reverse!` requires argument 1 to be: Block, String, List.
reverse! ref { 3 2 1 3 }
; returns { 3 2 1 3 }
x: ref list { 1 2 3 } , reverse! x , x
; returns list { 3 2 1 }
concat
Joins two series values together.
value1 First value (string, integer, block) to concatenate
value2 Second value to concatenate with the first
returns result of concatenating the two values
"abcd" .concat "cde"
; returns "abcdcde"
concat { 1 2 3 4 } { 2 4 5 }
; returns { 1 2 3 4 2 4 5 }
123 .concat "abc"
; returns "123abc"
_++
Joins two values together, with behavior depending on types: concatenates strings, joins blocks, merges dictionaries, etc.
value1 First value (string, block, dict, etc.)
value2 Second value to join
returns result of joining the values, type depends on input types
"A" ++ "b"
; returns "Ab"
"A" ++ 1
; returns "A1"
{ 1 2 } ++ { 3 4 }
; returns { 1 2 3 4 }
dict { "a" 1 } || ++ { "b" 2 }
; returns dict { a 1 b 2 }
dict { "a" 1 } || ++ dict { "b" 2 }
; returns dict { a 1 b 2 }
union
Combines two collections, removing any duplicate values to create a union of all unique values.
collection1 First block or list
collection2 Second block or list
returns a new collection containing all unique values from both collections
union { 1 2 3 4 } { 2 4 5 } |length?
; returns 5
union list { 1 2 3 4 } list { 2 4 5 } |length?
; returns 5
union { 8 2 } { 1 9 } |sort
; returns { 1 2 8 9 }
union { 1 2 } { } |sort
; returns { 1 2 }
union { } { 1 9 } |sort
; returns { 1 9 }
union { } { }
; returns { }
union list { 1 2 } list { 1 2 3 4 } |sort
; returns list { 1 2 3 4 }
union list { 1 2 } list { 1 } |sort
; returns list { 1 2 }
union list { 1 2 } list { } |sort
; returns list { 1 2 }
union list { } list { 1 2 } |sort
; returns list { 1 2 }
union list { } list { }
; returns list { }
range
Creates a block containing all integers from the start value to the end value, inclusive.
start Integer starting value (inclusive)
end Integer ending value (inclusive)
returns a block containing all integers from start to end, inclusive
range 1 5
; returns { 1 2 3 4 5 }
range 5 10
; returns { 5 6 7 8 9 10 }
range -2 2
; returns { -2 -1 0 1 2 }
is-empty
Checks if a collection is empty, returning 1 for empty collections and 0 otherwise.
collection String, block, dict, list, table, context or vector to check
returns integer 1 if the collection is empty, 0 otherwise
{ } .is-empty
; returns true
dict { } |is-empty
; returns true
table { 'a 'b } { } |is-empty
; returns true
"abc" .is-empty
; returns false
{ 1 2 3 } .is-empty
; returns false
length?
Returns the number of elements in a collection.
collection String, block, dict, list, table, context or vector to measure
returns integer count of elements in the collection
{ 1 2 3 } .length?
; returns 3
length? "abcd"
; returns 4
table { 'val } { 1 2 3 4 } |length?
; returns 4
vector { 10 20 30 } |length?
; returns 3
dict { "a" 1 "b" 2 } |length?
; returns 2
keys
Extracts the keys from a dictionary or column names from a table as a block.
collection Dict or table to extract keys from
returns block containing all keys from the dictionary or column names from the table
dict { "a" 1 "b" 2 "c" 3 } |keys |length?
; returns 3
table { "a" "b" "c" } { 1 2 3 } |keys |length?
; returns 3
_->
Accesses a value in a collection by index or key (1-based indexing for blocks and lists).
collection Block, list, dict or other indexable collection
index Index or key to access
returns value at the specified index or key
{ 23 34 45 } |-> 1
; returns 34
{ "a" "b" "c" } |-> 0
; returns "a"
dict { "a" 1 "b" 2 } |-> "b"
; returns 2
_<-
Accesses a value in a collection by index or key, with reversed argument order (0-based indexing for blocks and lists).
index Index or key to access
collection Block, list, dict or other indexable collection
returns value at the specified index or key
0 <- { 23 34 45 }
; returns 23
2 <- { "a" "b" "c" }
; returns "c"
"a" <- dict { "a" 1 "b" 2 }
; returns 1
_<~
Accesses a value in a collection by index with reversed argument order (1-based indexing).
index Index to access (1-based)
collection Block, list or other indexable collection
returns value at the specified index
2 <~ { 23 34 45 }
; returns 34
1 <~ { "a" "b" "c" }
; returns "a"
_~>
Accesses a value in a collection by index (0-based indexing).
collection Block, list or other indexable collection
index Index to access (0-based)
returns value at the specified index
{ 23 34 45 } |~> 1
; returns 23
{ "a" "b" "c" } |~> 1
; returns "a"
intersection
Finds the common elements between two collections, returning only values that appear in both.
collection1 First string, block or list
collection2 Second string, block or list (same type as first)
returns a new collection containing only values that appear in both input collections
"abcd" .intersection "cde"
; returns "cd"
intersection { 1 2 3 4 } { 2 4 5 }
; returns { 2 4 }
intersection { 1 3 5 6 } { 2 3 4 5 }
; returns { 3 5 }
intersection { 1 2 3 } { }
; returns { }
intersection { } { 2 3 4 }
; returns { }
intersection { 1 2 3 } { 4 5 6 }
; returns { }
intersection { } { }
; returns { }
intersection list { 1 3 5 6 } list { 2 3 4 5 }
; returns list { 3 5 }
intersection list { 1 2 3 } list { }
; returns list { }
intersection list { } list { 2 3 4 }
; returns list { }
intersection list { 1 2 3 } list { 4 5 6 }
; returns list { }
intersection list { } list { }
; returns list { }
intersection\by
Finds the intersection of two collections using a custom comparison function to determine matching elements.
collection1 First string or block
collection2 Second string or block
comparator Function that takes two arguments and returns a truthy value if they should be considered matching
returns a new collection containing values from the first collection that match with values from the second collection according to the comparator
intersection\by "foobar" "fbx" fn { a b } { a .contains b }
; returns "fb"
intersection\by "fooBar" "Fbx" fn { a b } { a .to-lower .contains to-lower b }
; returns "fB"
intersection\by { "foo" 33 } { 33 33 } fn { a b } { a .contains b }
; returns { 33 }
intersection\by { "foo" "bar" 33 } { 42 } fn { a b } { map a { .type? } |contains b .type? }
; returns { 33 }
intersection\by { { "foo" x } { "bar" y } } { { "bar" z } } fn { a b } { map a { .first } |contains first b }
; returns { { "bar" y } }
difference
Creates a new collection containing elements from the first collection that are not present in the second collection.
collection1 First string, block or list
collection2 Second string, block or list (same type as first)
returns a new collection containing values from the first collection that do not appear in the second collection
"abcde" .difference "cde"
; returns "ab"
difference { 1 2 3 4 } { 2 4 }
; returns { 1 3 }
difference list { "Bob" "Sal" "Joe" } list { "Joe" }
; returns list { "Bob" "Sal" }
difference "abc" "bc"
; returns "a"
difference "abc" "abc"
; returns ""
difference "abc" ""
; returns "abc"
difference "" ""
; returns ""
difference { 1 3 5 6 } { 2 3 4 5 }
; returns { 1 6 }
difference { 1 2 3 } { }
; returns { 1 2 3 }
difference { } { 2 3 4 }
; returns { }
difference { } { }
; returns { }
difference list { 1 3 5 6 } list { 2 3 4 5 }
; returns list { 1 6 }
difference list { 1 2 3 } list { }
; returns list { 1 2 3 }
difference list { } list { 2 3 4 }
; returns list { }
difference list { } list { }
; returns list { }
transpose
Transposes a matrix (block of blocks), converting rows to columns and columns to rows.
matrix Block of blocks representing a matrix
returns transposed matrix (rows become columns and columns become rows)
{ { 1 2 3 } { 4 5 6 } } .transpose
; returns { { 1 4 } { 2 5 } { 3 6 } }
{ { 1 4 } { 2 5 } { 3 6 } } .transpose
; returns { { 1 2 3 } { 4 5 6 } }
remove-last!
Removes the last element from a block in-place and returns the modified block.
word Word referring to a block to modify
returns the modified block with the last element removed
var 'x ref { 1 2 3 4 } remove-last! 'x x
; returns { 1 2 3 }
var 'x ref { 1 2 3 4 } remove-last! 'x
; returns { 1 2 3 }
append!
Appends a value to a block, list or string in-place and returns the modified collection.
value Value to append
word Word referring to a block, list or string to modify
returns the modified collection with the value appended
var 'x ref { 1 2 3 } append! 4 'x , x
; returns { 1 2 3 4 }
var 's "hello" append! " world" 's , s
; returns "hello world"
change\ th!
Changes the value at a specific position in a block or list in-place and returns the modified collection.
collection Reference to a block or list to modify
position Position of the element to change (1-based)
value New value to set at the specified position
returns the modified collection with the value changed at the specified position
x: ref { 1 222 3 } change\nth! x 2 222 , x
; returns { 1 222 3 }
x: ref list { "a" "b" "c" } change\nth! x 1 "X" , x
; returns list { "X" "b" "c" }
peek
Returns the current value at a block's cursor position without advancing the cursor.
block Block to peek at
returns the current value at the block's cursor position without advancing the cursor
x: { 1 2 3 } peek x
; returns 1
pop
Returns the current value at a block's cursor position and advances the cursor.
block Block to pop from
returns the current value at the block's cursor position, advancing the cursor
x: { 1 2 3 } pop x
; returns 1
pos
Returns the current cursor position in a block.
block Block to get position from
returns the current cursor position in the block
x: { 1 2 3 } pos x
; returns 0
x: { 1 2 3 } pos next x
; returns 1
next
Advances the cursor position in a block and returns the block.
block Block to advance cursor in
returns the block with its cursor advanced to the next position
x: { 11 22 33 } peek next next x
; returns 33
vals
Takes a block of Rye values and evaluates each value or expression.
x: 1 y: 2 vals { x y }
; returns { 1 2 }
x: 1 y: 2 vals { 1 y }
; returns { 1 2 }
x: 1 y: 2 try { vals { z y } } |type?
; returns error
vals\with
Evaluate a block with injecting the first argument.
x: 1 y: 2 vals\with 10 { + x , * y }
; returns { 11 20 }
x: 1 y: 2 vals\with 100 { + 10 , * 8.9 }
; returns { 110 890 }
Contexts
Context related functions
raw-context
Creates a completely isolated context with no parent, where only built-in functions are available.
block Block of expressions to evaluate in a new isolated context
returns context object with the values defined in the block
c: raw-context { x: 123 } c/x
; returns 123
y: 123 try { c: raw-context { x: y } } |type?
; returns error
try { c: raw-context { x: inc 10 } } |type?
; returns error
isolate
Creates a context that can access the parent context during creation, but becomes isolated afterward.
block Block of expressions to evaluate in a temporary context
returns context object with the values defined in the block, but isolated from parent contexts
c: isolate { x: 123 } c/x
; returns 123
y: 123 c: isolate { x: y } c/x
; returns 123
c: isolate { x: inc 10 } c/x
; returns 11
y: 99 c: isolate { x: does { y } } try { c/x } |type?
; returns error
y: 99 c: isolate { t: ?try x: does { t { y } } } c/x |type?
; returns error
context
Creates a new context that maintains access to its parent context.
block Block of expressions to evaluate in a new context
returns context object with the values defined in the block and access to parent context
c: context { x: 123 } c/x
; returns 123
y: 123 c: context { x: y } c/x
; returns 123
c: context { x: inc 10 } c/x
; returns 11
y: 123 c: context { x: does { y } } c/x
; returns 123
private
Creates a temporary private context for evaluating expressions, returning the last value instead of the context.
block Block of expressions to evaluate in a private context
returns the last value from evaluating the block (not the context itself)
private { x: 123 }
; returns 123
y: 123 private { x: y }
; returns 123
private { x: inc 10 }
; returns 11
y: 123 private { does { y } } :f f
; returns 123
private\
Creates a documented private context for evaluating expressions, returning the last value instead of the context.
doc String containing documentation for the context
block Block of expressions to evaluate in a private context
returns the last value from evaluating the block (not the context itself)
private\ "what are we doing here" { x: 234 1000 + x }
; returns 1234
extends
Creates a new context that inherits from a specified parent context.
parent Context object to extend
block Block of expressions to evaluate in the new context
returns new context object that inherits from the parent context
ct: context { p: 123 } cn: extends ct { r: p + 234 } cn/r
; returns 357
bind!
Binds a context to a parent context, allowing it to access the parent's values.
child Context object to be bound
parent Context object to bind to as parent
returns the modified child context with its parent set to the specified parent context
c: context { y: 123 } cc: bind! context { z: does { y + 234 } } c , cc/z
; returns 357
unbind
Removes the parent relationship from a context, making it a standalone context.
ctx Context object to unbind from its parent
returns the modified context with no parent
c: context { y: 123 } cc: bind! context { z: does { y + 234 } } c , unbind cc cc/z
; returns 357
c: context { y: 123 } cc: bind! context { z: does { y + 234 } } c , dd: unbind cc dd/z
; correctly causes error:
; word not found: y
current
Returns current context.
c: context { var 'x 9999 , incr: fn\in { } current { x:: inc x } } c/incr c/x
; returns 10000
parent
Returns parent context of the current context.
var 'y 99 c: context { incr: fn\in { } parent { y:: inc y } } c/incr y
; returns 100
parent\of
Returns parent context of the current context.
ct: context { p: 123 } parent\of ct |= current
; returns true
clone
Creates a copy of a context with the same state and parent relationship.
ctx Context object to clone
returns a new context object that is a copy of the original context
c: context { x: 123 y: 456 } cc: clone c cc/x
; returns 123
c: context { x: 123 y: 456 } cc: clone c cc/y
; returns 456
c: context { x:: 123 } cc: clone c do\in cc { x:: 999 } c/x
; returns 123
c: context { x:: 123 } cc: clone c do\in cc { x:: 999 } cc/x
; returns 999
clone\
Creates a copy of a context and evaluates a block of code inside the clone.
ctx Context object to clone
block Block of expressions to evaluate in the cloned context
returns the cloned context with the block evaluated inside it
c: context { x: 123 } cc: clone\ c { y: x + 100 } cc/y
; returns 223
Functions
functions that create functions
var
Declares a word as a variable with the given value, allowing it to be modified. Can only be used once per word in a context.
word Tagword representing the variable name
value Initial value for the variable
returns The initial value
var 'x 10 x:: 20 x
; returns 20
does
Creates a function with no arguments that executes the given block when called.
body Block containing the function body code
returns function object with no parameters
does { 123 } |type?
; returns function
x: does { 123 } x
; returns 123
x: does { 1 + 2 } x
; returns 3
fn1
Creates a function that accepts one anonymous argument and executes the given block with that argument.
body Block containing the function body code
returns function object that accepts one anonymous argument
fn1 { .pass { } } |type?
; returns function
x: fn1 { } , x 123
; returns 123
x: fn1 { .pass { } } , x 123
; returns 123
x: fn1 { + 1 } , x 123
; returns 124
fn
Creates a function with named parameters specified in the first block and code in the second block.
spec Block containing parameter specifications
body Block containing the function body code
returns function object with the specified parameters
fn { } { } |type?
; returns function
x: fn { } { 234 } , x
; returns 234
x: fn { x } { x } , x 123
; returns 123
x: fn { x } { + 123 } , x 123
; returns 246
pfn
Creates a pure function (no side effects allowed) with named parameters and code body.
spec Block containing parameter specifications
body Block containing the function body code
returns pure function object with the specified parameters
pfn { } { } |type?
; returns function
x: pfn { x } { + 123 } , x 123
; returns 246
fn\cc
Creates a function that captures the current context, allowing access to variables from the enclosing scope.
spec Block containing parameter specifications
body Block containing the function body code
returns function object with the current context captured
fn\cc { x } { x + y } |type?
; returns function
y: 5 , f: fn\cc { x } { x + y } , f 3
; returns 8
fn\par
Creates a function with a specified parent context, allowing access to variables from that context.
spec Block containing parameter specifications
context Context object to use as parent context
body Block containing the function body code
returns function object with the specified parent context
ctx: context { y: 5 } , f: fn\par { x } ctx { x + y } , f 3
; returns 8
fn\in
Creates a function that executes directly in the specified context rather than creating a new execution context.
spec Block containing parameter specifications
context Context object to execute the function in
body Block containing the function body code
returns function object that executes directly in the specified context
ctx: context { y: 5 } , f: fn\in { x } ctx { x + y } , f 3
; returns 8
closure
Creates a closure that captures the current context at creation time, preserving access to variables in that scope.
spec Block containing parameter specifications
body Block containing the function body code
returns function object that captures the current context at creation time
y: 5 , f: closure { x } { x + y } , f 3
; returns 8
partial
Creates a partially applied function with specified arguments, using _ (void) for arguments to be filled later.
func Function or builtin to partially apply
args Block of arguments, with _ (void) for arguments to be filled later
returns CurriedCaller object that can be called with the remaining arguments
prepend-star: partial ?concat [ "* " _ ] , prepend-star "hello"
; returns "* hello"
add-5: partial ?_+ [ _ 5 ] , add-5 10
; returns 15
fn-add: fn { x y } { x + y } , add-5: partial ?fn-add [ _ 5 ] , add-5 10
; returns 15
Other
...
change!
Searches for a word and changes it's value in-place. Only works on variables declared with var. If value changes returns true otherwise false
value New value to assign to the word
word Word whose value should be changed
returns Integer 1 if the value changed, 0 if the new value is the same as the old value
var 'x 123 , change! 234 'x , x
; returns 234
a:: 123 change! 333 'a a
; returns 333
a:: 123 change! 124 'a
; returns 1
a:: 123 change! 123 'a
; returns 0
set!
Set word to value or words by deconstructing a block. Only works on variables declared with var.
values Value or block of values to assign to the word(s)
words Word or block of words to be set
returns The value or block of values that was assigned
set! { 123 234 } { a b } b
; returns 234
unset!
Unset a word in current context, only meant to be used in console
word Word to be unset from the current context
returns Void value
x: 1 unset! 'x x: 2
; returns 2
val
Returns value of the word in context
word Word whose value should be retrieved
returns The value associated with the word in the current context
x: 123 val 'x
; returns 123
x: 123 y: 'x val y
; returns 123
_<<
Converts a value to specific kind (R to L)
kind Kind to convert the value to
value Dict or context to convert
returns A new context of the specified kind
_|
Pipeline operator that passes the value through unchanged (used with 'not' and other operations).
value Any value to be passed through unchanged
returns the original value (used in pipeline operations for explicit pass-through)
5
; returns 5
"hello"
; returns "hello"
true
; returns true
{ 1 2 3 }
; returns { 1 2 3 }
save\current
Saves current state of the program to a file.
None
returns Integer 1 on success
save\current |type?
; returns integer
save\current\secure
Saves current state of the program to a file with password protection.
None
returns Integer 1 on success
doc!
Sets docstring of the current context.
doc String to set as the docstring for the current context
returns Integer 1 on success
x: private { doc! "some doc" doc? }
; returns "some doc"
doc?
Gets docstring of the current context.
None
returns String containing the docstring of the current context
x: private { doc! "some doc" doc? }
; returns "some doc"
doc\of?
Get docstring of the passed context.
value Function, builtin, or context to get the docstring from
returns String containing the docstring of the provided value
x: context { doc! "some doc" } doc\of? x
; returns "some doc"
ref
Makes a value mutable instead of immutable
value Value to make mutable
returns A mutable reference to the value
is-ref ref { 1 2 3 }
; returns true
deref
Makes a value again immutable
value Mutable reference to make immutable
returns An immutable copy of the value
is-ref deref ref { 1 2 3 }
; returns false
is-ref
Checks if a value is a mutable reference.
value Any value to check if it's a reference
returns Integer 1 if the value is a reference, 0 otherwise
ref { } |is-ref
; returns true
{ } |is-ref
; returns false
dict
Constructs a Dict from the Block of key and value pairs.
block Block containing alternating keys and values
returns A new Dict with the specified keys and values
dict { "a" 123 } |-> "a"
; returns 123
list
Constructs a List from the Block of values.
block Block containing values to put in the list
returns A new List with the values from the block
list { "a" 123 } |-> 0
; returns "a"
import
Imports a file, loads and does it from script local path.
uri URI of the file to import and execute
returns result of executing the imported file
import\live
Imports a file, loads and does it from script local path.
uri URI of the file to import, execute, and watch for changes
returns result of executing the imported file
load
Loads a string into Rye values.
source String containing Rye code or URI of file to load
returns Block containing the parsed Rye values
load " 1 2 3 " |third
; returns 3
load "{ 1 2 3 }" |first |third
; returns 3
load\mod
Loads a string into Rye values. During load it allows modification of words.
source String containing Rye code or URI of file to load with modification allowed
returns Block containing the parsed Rye values
load\live
Loads a string into Rye values. During load it allows modification of words.
source String containing Rye code or URI of file to load with modification allowed and file watching
returns Block containing the parsed Rye values
load\sig
Checks the signature, if OK then loads a string into Rye values.
source String containing signed Rye code to verify and load
returns Block containing the parsed Rye values if signature is valid
do
Takes a block of code and does (runs) it.
block Block of code to execute
returns result of executing the block
do { 123 + 123 }
; returns 246
do { 123 + }
; correctly causes error:
; argument 2 of 2 missing of builtin: 'Adds or joins two values together, with behavior depending on types: adds numbers, concatenates strings/blocks, merges dictionaries, etc. (base) (_+)'
do { _+ _+ 12 23 34 }
; returns 69
do { 12 * 23 |+ 34 }
; returns 310
do { ( 12 * 23 ) + 34 }
; returns 310
do { 12 * 23 || + 34 }
; returns 310
do { 12 * 23 :a + 34 }
; returns 310
do { 12 * 23 :a a + 34 }
; returns 310
with
Takes a value and a block of code. It does the code with the value injected.
value Value to inject into the block's execution context
block Block of code to execute with the injected value
returns result of executing the block with the injected value
with 100 { + 11 }
; returns 111
with 100 { + 11 , * 3 }
; returns 300
do\in
Takes a Context and a Block. It Does a block inside a given Context.
context Context in which to execute the block
block Block of code to execute within the specified context
returns result of executing the block within the given context
c: context { x: 100 } do\in c { x * 9.99 }
; returns 999
c: context { x:: 100 } do\in c { inc! 'x }
; returns 101
c: context { var 'x 100 } do\in c { x:: 200 } c/x
; returns 200
c: context { x:: 100 } do\in c { x:: 200 , x }
; returns 200
do\par
Takes a Context and a Block. It Does a block in current context but with parent a given Context.
context Context to use as parent context during execution
block Block of code to execute in current context with the specified parent context
returns result of executing the block with the modified parent context
c: context { x: 100 } do\par c { x * 9.99 }
; returns 999
c: context { x:: 100 } do\par c { inc! 'x }
; returns 101
c: context { x: 100 } do\par c { x:: 200 , x }
; returns 200
c: context { x: 100 } do\par c { x:: 200 } c/x
; returns 100
return
Accepts one value and returns it.
x: fn { } { return 101 202 } x
; returns 101
cmd
Execute a shell command.
cmd "echo "hello""
; returns 1
rye
rye .type?
; returns native
defer
Registers a block of code to be executed when the current function exits or the program terminates.
345
; returns 123
ff:: fn { } { var 'x 123 defer { print 234 } x } , ff
; prints "234
; "
ff:: fn { } { x:: 123 defer { x:: 234 } x + 111 } , ff
; returns 234
defer\
Registers a block of code with an injected value to be executed when the current function exits or the program terminates. Works like 'with' but deferred.
value Value to inject into the deferred block
block Block to execute with the injected value when function exits
returns Void value
43
; returns 0
ff:: fn { } { defer\ "hello" { .print } "done" } , ff
; prints "hello
; "