Skip to content
Open Saka

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 num

Numbers: 64-bit floating point (IEEE binary64), with one zero and one nan.

str

set str

Text: sequences of Unicode scalar values.

bool

set bool

The two Boolean values, false and true.

ref

set ref

Refs: the identities of things in a database, such as the members of a role. A ref keeps its identity forever.

proc ref()! ref

Makes a new ref, with an identity no other ref has.

pos

set pos

Positions that keep items in a chosen order.

uuid

set uuid

Universally unique identifiers (UUIDs) of every version.

none

lex none

The empty lexical domain; no scalar belongs to it.

any

lex any

The unrestricted lexical domain for Unicode scalar sequences.

char

lex char

The lexical domain of exactly one Unicode scalar.

Constants

false

set false = bool:false

The singleton Set containing Boolean false.

def false! false

One occurrence of Boolean false.

true

set true = bool:true

The singleton Set containing Boolean true.

def true! true

One occurrence of Boolean true.

nan

set nan = num:nan

The singleton Set containing the canonical not-a-number value.

def nan! nan

One occurrence of the canonical not-a-number value.

inf

set inf = num:inf

The singleton Set containing positive infinity.

def inf! inf

One occurrence of positive infinity.

void

qset void = ()'0

The contract of a procedure that returns nothing: no occurrences of the empty Tuple ().

Pattern contracts

never

qlex never

The 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 | upper

Recognizes one ASCII letter of either case.

alnum

reg alnum! char = alpha | digit

Recognizes 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! char

Recognizes 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 | vspace

Recognizes 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 -> T

Relates 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)* T

The 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)! num

Returns the total multiplicity, including zero for an empty Bag.

exists

def exists[set T](values* T)! bool

True when the Bag holds at least one occurrence, whatever its Values; an empty Bag produces false.

empty

def empty[set T](values* T)! bool

True when the Bag holds no occurrences.

has

def has[set T](haystack* T, needle! T)! bool

True when the haystack holds the needle’s Value, whatever its multiplicity. To search within text, use str::contains.

sum

def sum(values* num)! num

Sums 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)'kv

Exchanges the key and value of each Map entry, preserving multiplicity.

all

def all(values* bool)! bool

True when every occurrence is true; an empty Bag produces true.

any

def any(values* bool)! bool

True when at least one occurrence is true; an empty Bag produces false.

not

def not(values* bool): bool'values

Negates every Boolean occurrence, preserving multiplicity.

Output, parsers, and modules

print

proc print(message! str): void

Prints 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.