prelude
The names that every module can use without a prefix: the basic Sets, such as num and str, functions of
whole Bags, such as count and sum, character patterns, and the other modules of the standard library.
Keywords and operators, such as map and +, belong to the language, not to the prelude. Declarations without a
body are built into the compiler; the others are ordinary SakaQL.
These names are available everywhere, without a prefix.
Basic Sets
num
set numNumbers: 64-bit floating point (IEEE binary64), with one zero and one nan.
str
set strText: sequences of Unicode scalar values.
bool
set boolThe two Boolean values, false and true.
ref
set refRefs: the identities of things in a database, such as the members of a role. A ref keeps its identity forever.
proc ref()! refMakes a new ref, with an identity no other ref has.
pos
set posPositions that keep items in a chosen order.
uuid
set uuidUniversally unique identifiers (UUIDs) of every version.
none
lex noneThe empty lexical domain; no scalar belongs to it.
any
lex anyThe unrestricted lexical domain for Unicode scalar sequences.
char
lex charThe lexical domain of exactly one Unicode scalar.
Constants
false
set false = bool:falseThe singleton Set containing Boolean false.
def false! falseOne occurrence of Boolean false.
true
set true = bool:trueThe singleton Set containing Boolean true.
def true! trueOne occurrence of Boolean true.
nan
set nan = num:nanThe singleton Set containing the canonical not-a-number value.
def nan! nanOne occurrence of the canonical not-a-number value.
inf
set inf = num:infThe singleton Set containing positive infinity.
def inf! infOne occurrence of positive infinity.
void
qset void = ()'0The contract of a procedure that returns nothing: no occurrences of the empty Tuple ().
Pattern contracts
never
qlex neverThe contract of a pattern that never matches.
many
qlex many = any'*An unrestricted sequence in the any lexical domain.
Character patterns
digit
reg digit! char = "0".."9"Recognizes one ASCII decimal digit.
lower
reg lower! char = "a".."z"Recognizes one lowercase ASCII letter.
upper
reg upper! char = "A".."Z"Recognizes one uppercase ASCII letter.
alpha
reg alpha! char = lower | upperRecognizes one ASCII letter of either case.
alnum
reg alnum! char = alpha | digitRecognizes one ASCII letter or decimal digit.
hex
reg hex! char = digit | "a".."f" | "A".."F"Recognizes one ASCII hexadecimal digit of either case.
cntrl
reg cntrl! char = {"\u{0}".."\u{1F}", "\u{7F}"}Recognizes one ASCII control scalar, including DEL.
punct
reg punct! char = {"!".."/", ":".."@", "[".."`", "{".."~"}Recognizes one ASCII punctuation scalar.
newline
reg newline! char = "\n"Recognizes a line feed (U+000A).
vspace
reg vspace! char = {"\n", "\r", "\u{2028}", "\u{2029}"}Recognizes line feed, carriage return, or Unicode line/paragraph separators.
hspace
reg hspace! charRecognizes one horizontal whitespace scalar: tab, vertical tab, form feed, space, no-break space, Ogham space mark, U+2000 through U+200A, narrow no-break space, medium mathematical space, ideographic space, or byte order mark.
wspace
reg wspace! char = hspace | vspaceRecognizes the union of horizontal and vertical whitespace; also defines string trimming.
Functions of whole Bags
distinct
def distinct[set T](values* T): T'values%Keeps one occurrence of every distinct input value.
transitive_closure_map
def transitive_closure_map[set T](kv* T -> T)* T -> TRelates every pair joined by a path of one or more Maps of kv, once each.
reachable
def reachable[set T](start* T, edges* T -> T)* TThe Values that one or more Maps of edges lead to from start, once each, found by searching from start
alone; start itself is included only when a cycle leads back to it.
count
def count[set T](values* T)! numReturns the total multiplicity, including zero for an empty Bag.
exists
def exists[set T](values* T)! boolTrue when the Bag holds at least one occurrence, whatever its Values; an empty Bag produces false.
empty
def empty[set T](values* T)! boolTrue when the Bag holds no occurrences.
has
def has[set T](haystack* T, needle! T)! boolTrue when the haystack holds the needle’s Value, whatever its multiplicity. To search within text, use
str::contains.
sum
def sum(values* num)! numSums numeric occurrences, including multiplicity; an empty Bag produces zero.
avg
def avg(values* num): num'values#Averages numeric occurrences by multiplicity; an empty Bag produces an empty Bag.
min
def min[set T](values* T): T'values#Returns one occurrence of the least input value; an empty Bag produces an empty Bag.
max
def max[set T](values* T): T'values#Returns one occurrence of the greatest input value; an empty Bag produces an empty Bag.
reverse
def reverse[set K, set V](kv* K -> V): (V -> K)'kvExchanges the key and value of each Map entry, preserving multiplicity.
all
def all(values* bool)! boolTrue when every occurrence is true; an empty Bag produces true.
any
def any(values* bool)! boolTrue when at least one occurrence is true; an empty Bag produces false.
not
def not(values* bool): bool'valuesNegates every Boolean occurrence, preserving multiplicity.
Output, parsers, and modules
print
proc print(message! str): voidPrints a message once the action that calls it succeeds, so a failed action prints nothing.
compile_parser
mod compile_parser(grammar)Builds a parser module from a grammar.
reflect
use mod reflect = "@std/reflect.saka"The database’s own declarations, as roles to query.
See reflect.
num
use mod num = "@std/num.saka"Numbers: constants, math, tests, integer ranges, and conversion to and from text.
See num.
str
use mod str = "@std/str.saka"Text: length, search, slices, case, padding, trimming, and splitting.
See str.
re
use mod re = "@std/re.saka"Search, split, and replace text with patterns.
See re.
pos
use mod pos = "@std/pos.saka"Positions that keep items in a chosen order.
See pos.
rand
use mod rand = "@std/rand.saka"Random numbers, not for secrets.
See rand.
uuid
use mod uuid = "@std/uuid.saka"UUIDs: their versions, their text, and version modules such as uuid::v7.
See uuid.
color
use mod color = "@std/color.saka"Colors as numbers that a picture draws: rgb, gray, hsl, and the named colors of CSS, such as color::steelblue.
See color.