The BoaC Programming Guide - Built-In Functions
BoaC provides several useful built-in functions. For reference, these functions are described in this section.
Array Functions
Date & Time Functions
Map Functions
Math Functions
Other Functions
Queue Functions
Set Functions
Stack Functions
String Functions
Type Conversion Functions
Array Functions
Returns a new array of the same type as a
, of size n
, and with all elements initialized to the value v
.
Returns the sorted version of an array. Only scalar values can be sorted. Values will be arranged in increasing order.
Date & Time Functions
Return the time, n
days after the given time t
. The value of n
may be negative, or n
may be absent altogether, in which case n
defaults to 1. An optional third argument gives the timezone
.
Return the time, n
months after the given time t
. The value of n
may be negative, or n
may be absent altogether, in which case n
defaults to 1. An optional third argument gives the timezone
.
Return the time, n
weeks after the given time t
. The value of n
may be negative, or n
may be absent altogether, in which case n
defaults to 1. An optional third argument gives the timezone
.
Return the time, n
years after the given time t
. The value of n
may be negative, or n
may be absent altogether, in which case n
defaults to 1. An optional third argument gives the timezone
.
The numeric day of the month; for January 17, return 17, etc. An optional second argument names a timezone
.
The numeric day of the week, from Monday=1 to Sunday=7. An optional second argument names a timezone
.
The numeric day of the year. January 1 is day 1. An optional second argument names a timezone
.
Return a string containing the time argument formatted according to the format
string. The syntax of the format string is the same as in ANSI C strftime. An optional third argument names a timezone
.
The numeric hour of the day, from 0 to 23. Midnight is 0, 1AM is 1, etc. An optional second argument names a timezone
.
The numeric minute of the hour, from 0 to 59. An optional second argument names a timezone
.
The numeric month of the year. January is 1. An optional second argument names a timezone
.
Return the current time at the moment of execution. Note that the time value returned does not depend on a timezone.
The numeric second of the minute, from 0 to 59. An optional second argument names a timezone
.
Truncate t
to the zeroth microsecond of the day. Useful when creating variables indexed to a particular day, since all times in the day truncated with trunctoday will fold to the same value, which is the first time value in that day. An optional second argument names a timezone
.
Truncate t
to the zeroth microsecond of the hour. An optional second argument names a timezone
.
Truncate t
to the zeroth microsecond of the minute. An optional second argument names a timezone
.
Truncate t
to the zeroth microsecond of the month. An optional second argument names a timezone
.
Truncate t
to the zeroth microsecond of the second. An optional second argument names a timezone
.
Truncate t
to the zeroth microsecond of the year. An optional second argument names a timezone
.
The numeric year value, such as 2003. An optional second argument names a timezone
.
Map Functions
Clears all values from the map m
.
@since 2019-10
Creates a clone of the map m
.
Return a boolean reporting whether the key
is present in the map m
.
Return an array holding, in no particular order, the set of keys present in the map m
.
Return the element of the map m
indexed by the key
or, if there is no such element, the specified default value
. Assuming the map, key, and value are defined, equivalent to: def(m[key]) ? m[key] : value
Removes the entry for the key k
, if it exists in themap.
Return an array holding, in no particular order, the set of values present in the map m
.
Math Functions
Return an integer representing the bit position of the highest one bit in n
. If n
is zero, the result is 0; if n
is 1, the result is 1, if n
is 15, the result is 4, etc.
Return a random floating point number x
in the range 0.0 < x
< 1.0.
Other Functions
Returns a boolean value according to whether v
has a defined value.
The hash function returns a hash of the argument v
, which may be of any type.
Queue Functions
Clears all values from the queue q
.
Offers the value val
to the queue q
.
Returns the latest value on the queue q
without removing it from the queue.
Polls the queue q
and removes the oldest value and returns it.
Return an array holding the values present in the queue q
.
Set Functions
Adds the value v
to the set.
Clears all values from the set s
.
@since 2019-10
Creates a clone of the set s
.
Returns if the set s1> contains all of the values in set
s2
.
Returns the set s1
with all values from s2
removed.
Returns a set containing all values in both the sets s1
and s2
.
Removes the value v
from the set, if it contains it.
Equivalent to union(difference(s1, s2), difference(s2, s1))
.
Returns a set containing all values in either the set s1
or the set s2
.
Return an array holding the values present in the set s
.
Stack Functions
Clears all values from the stack s
.
Returns the last value on the stack s
without removing it from the stack.
Pops the last value off the stack s
and returns it.
Pushes the value val
onto the stack s
.
Return an array holding the values present in the stack s
.
String Functions
Return a string containing the arguments formatted according to the format
string. The syntax of the format string is essentially that of ANSI C with the following differences:
- %b prints a boolean, "true" or "false".
- %c prints a (u)int as a Unicode character in UTF-8.
- %k like %c with single quotes and backslash escapes for special characters.
- %s prints a string as UTF-8.
- %q like %s with double quotes and backslash escapes for special characters.
- %t prints a time, in the format of the Unix function ctime without a newline.
- %T prints the type of the argument; %#T expands user-defined types.
- %d / %i / %o / %u / %x / %X apply to a (u)int and have no 'l' or 'h' modifiers.
- %e / %f / %g / %E / %G apply to a float and have no 'l' or 'h' modifiers.
format verbs 'n' and '*' are not supported.
Returns a copy of the given string str
with all characters lower-cased.
Search for a match of the regular expression regex
within str
, and return a boolean value indicating whether a match was found.
Search for a match of the regular expression regex
within str
, and return an array consisting of character positions within str
defined by the match. Positions 0 and 1 of the array report the location of the match of the entire expression, subsequent pairs report the location of matches of successive parenthesized subexpressions.
Search for a match of the regular expression regex within str, and return. The 0th string is the entire match; following elements of the array hold matches of successive parenthesized subexpressions. This function is equivalent to using matchposns to find successive locations of matches and created array slices of str with the indices returned.
Returns a string holding a regular expression suitable for matching text representing values of the specified type t
. For example, regex(int)
generates a string to match integer constants (-23, 0x1f, etc.). At the moment, only int and float types are supported. When the type is int, an optional numerical base
may be specified for the conversion.
Slice string s
into pieces according to subsequent matches of the regular expression regex
. Runs along the regular expression exactly once.
Slice string s
into pieces according to subsequent matches of the regular expression regex
. Runs along the regular expression until the input string is exhausted.
Slice string s
into pieces according to subsequent matches of the regular expression regex
. Runs along the regular expression at most n
times.
Search for the first occurrence of the needle
within haystack
and return the integer index of its first character, or -1 if it does not occur.
Return a copy of string haystack
, with non-overlapping instances of needle
replaced by replacement
. If replace_all
is false, only the first found instance is replaced.
Search for the last occurrence of the needle
within haystack
and return the integer index of its first character, or -1 if it does not occur.
Returns a substring of str
starting at start
(inclusive) and ending at end
(exclusive). If end
is not specified, the length of the string is used.
Returns a copy of the given string str
with all leading and trailing whitespace removed.
Returns a copy of the given string str
with all characters upper-cased.
Type Conversion Functions
Converts the value v
into a boolean value.
Converts the value v
into a float value.
Converts the value v
into an int value.
Converts the value v
into a string value.
Converts the value v
into a time value.