-
Notifications
You must be signed in to change notification settings - Fork 5
8.2) Metapredicates
Metapredicates are built-in predicates that are applied on predicates. They are represented by superscript letters and directly follow the predicate on which you want to apply them.
Just like built-in predicates, metapredicates also have an additional parameter called the superscript that directly follows the metapredicate name. It can either be a series of superscript digits or one of ⁽
and ⁾
to indicate that the first/last element of the input must be used as superscript (like built-in predicates and subscripts).
For example, the code pᶠ⁴²
can be read as "find the first 42 permutations of the input".
Metapredicates can be applied to inline predicates and predicate compositions as well. For example {p}ᶠ⁴²
would work as well.
You can use the subscript arrow ↖
to pass the immediately following variable as a superscript to a metapredicate (like ⁽
and ⁾
, in a shorter way that does not require the input to contain that variable).
For example, 13+₁ⁱ↖7
will output 20
.
Note that if you want to use both subscript and superscript arrows, they must both be used after the predicate and metapredicate combo.
For example, 13+ⁱ↙2↖7
or 13+ⁱ↖7↙2
will output 27
.
Symbol | Name | Superscript | Description |
---|---|---|---|
ᵃ |
Accumulate | Default = 1 I
|
Same as ⁱ but the Input at each step is the list of accumulated results. |
ᵇ |
Bagof | Default I
|
Same as ᶠ but uses bagof instead of findall under the hood |
ᶜ |
Count | Default = 0 1 |
Count all outputs of the predicate for ? Count all unique outputs of the predicate for ?
|
ᵈ |
Declare | Default 0 1 2 |
? = [A,B], . = B , call the pred. with A as input and B as output ? = . = [A,B] , call the pred. with A as input and B as output ? = [A,B], . = A , call the pred. with B as input and A as output ? = . = [A,B] , call the pred. with B as input and A as output |
ᵉ |
Existence | Default I |
The output of the pred. for at least one element of ? is . The output of the pred. for at least one element of ? = . is I
|
ᶠ |
Find | Default I
|
Find all outputs of the predicate for ? Find the first I outputs of the predicate for ?
|
ᵍ |
Group by | Default | Groups elements of ? together into . if they generate the same output to the predicate. |
ʰ |
Head | Default = 1 I |
Apply the predicate only to the head of ? Apply the predicate only to the first I elements of ?
|
ⁱ |
Iterate | Default I
|
Same as with superscript I with I > 0 not set Apply I times the predicate to ?
|
ʲ |
Default | ||
ᵏ |
Default | ||
ˡ |
Left fold | Default |
. is the left fold of the predicate on ?
|
ᵐ |
Map | Default = 1 I
|
Map the predicate to each element of ? Nested map I times on ?
|
ⁿ |
Nonexistence | Default I |
The output of the pred. for each element of ? is never . The output of the pred. for each element of ? = . is never I
|
ᵒ |
Order by | Default = 0 1 2 3 |
. is ? ordered asc. by mapping the predicate . is ? ordered desc. by mapping the predicate Same as 0 but . contains the elements of the map Same as 1 but . contains the elements of the map |
ᵖ |
Default | ||
ʳ |
Right fold | Default | Not implemented |
ˢ |
Select | Default | Find outputs of the predicate for each element of ?
|
ᵗ |
Tail | Default = 1 I |
Apply the predicate only to the tail of ? Apply the predicate only to the last I elements of ?
|
ᵘ |
Unique | Default I
|
Find all unique outputs of the pred. for ? Find the first I unique outputs of the pred. for ?
|
ᵛ |
Verify | Default I |
The output of the pred. for each element of ? is always . The output of the pred. for each element of ? = . is always I
|
ʷ |
Default | ||
ˣ |
Default | ||
ʸ |
Default | ||
ᶻ |
Zip | Default 0 1 2 |
Zip the input with the result of ᵐ on the pred. Zip the input with the result of ᶠ on the pred. Zip the result of ᵐ on the pred. with the input Zip the result of ᶠ on the pred. with the input |