Skip to content

3) Execution Control

Julien Cumin edited this page Oct 16, 2019 · 14 revisions

Execution Control

∧ & - Logical and

Logical and is implicit in Brachylog. is thus used mostly to break implicit unification.

For instance, 42 unifies both the Input and the Output with 42, whereas ∧42 will only unify the Output with 42.

& is the same as ∧?, that is break unification with the previous variable and choose the Input as the current variables.

- Logical or

As its name suggests, is used to denote logical or. Unlike | (to create a new rule, which is also a disjunction), the Input is not implicitely available after it. In fact, breaks implicit unification like .

Note: this character looks like v (the letter), but are in fact not the same.

, - Append

, will append inline a variable to the current variable. For example, 123,456 will result in 123456, [1,2],3 will result in [1,2,3], "test",3 will result in ["test",3].

; - Pair

; will pair inline a variable to the current variable. For example, 123;456 will result in [123,456], [1,2];3 will result in [[1,2],3], "test";3 will result in ["test",3].

( ) - Parentheses

Parentheses are used to group logical assertions together. The variable preceeding the opening parenthesis is implicitly available after that opening parenthesis. The last variable before the closing parenthesis is implicitly available after that closing parenthesis.

- Backtrack

is false, and will therefore trigger backtracking.

! - Cut

Ignore all preceeding choice point, which will thus not get explored when backtracking is triggered. This is equivalent to Prolog's cut (!).

` - Soft cut

Allows the construct <if>`<then>∨<else>. If <if> is true, then <then> is chosen and <else> is discarded, meaning you will at this point not reach <else> even when backtracking. You will however be able to backtrack on <if> and <then>. This is equivalent to Prolog's soft cut (*->).

¬ - Not Provable

True if the following assertion (a built-in predicate, or predicates contained in parentheses, or a predicate definition, or another variable which would unify with the current one) cannot be proven. This is equivalent to Prolog's \+.

~ - Reverse Arguments

The next predicate will be called with the variable to its left as Output and the variable to its right as Input.

For example, l will unify the Output with the length of the Input, whereas ~l will unify the Output with a list of N elements, if Input = N.

Note: when a predicate has a meta-predicate, ~ will apply to the predicate and not the meta-predicate.