Bags
A Bag is a collection of Values. A Value can appear more than once; its multiplicity is how many times it appears.
Build a Bag
Section titled “Build a Bag”Write Values of one kind between braces, separated by commas or new lines:
{1, 2, 2} // {1, 2'2}{ "red" "blue" "blue"} // {"blue"'2, "red"}A Bag has no order: the REPL lists its Values sorted. 'n repeats each occurrence n times:
"apple"'3 // {"apple"'3}{1, 2}'2 // {1'2, 2'2}% keeps one occurrence of each Value:
{1, 1, 2}% // {1, 2}Empty Bags
Section titled “Empty Bags”SakaQL has no null: missing data is an empty Bag. An empty Bag names the kind of Values it could hold, here num, the numbers:
num:{} // num:{}Sets explains names such as num.
Combine Bags
Section titled “Combine Bags”These operators combine two Bags of the same kind:
| Operation | Example | Result |
|---|---|---|
| Union: add the counts | {1, 1} | {1, 2} |
{1'3, 2} |
| Distinct union: keep one of each | {1, 1} |% {1, 2} |
{1, 2} |
| Difference: subtract the counts, down to zero | {1'3, 2} \+ {1, 2'2} |
{1'2} |
| Distinct difference | {1'3, 2} \% {1, 2'2} |
{1} |
| Product: multiply the counts of shared Values | {1'2, 2} & {1'3, 3} |
{1'6} |
| Distinct product | {1'2, 2} &% {1'3, 3} |
{1} |
| Fallback: the right Bag when the left one is empty | num:{} ?? {7, 8} |
{7, 8} |
{1, 1} | {1, 2} // {1'3, 2}