Standard Operators
cosmos-lang edited this page Jul 21, 2023
·
3 revisions
if
if(A) B else C;
1. A has the form `x=y` and both operands are atomic,
- It uses the reif optimization to avoid creating choice-points.
2.
- It is expanded to `(A and B) or (not A and C)`.
if(A) B;
- Similar to above. It applies the reif optimization if possible, otherwise expands to `if(A) B else not A;`.
not
1. The statement is an inequality,
- It's reversed, e.g. `not x<=1` expands to _x>1_, `not x=1` expands to _x!=1_.
2. If not,
- A compiler error will be given.
when
when(A) B else C;
- Expands to `(A and B) or C`.
if (function)
Compiles to choose
.
not (function)
Negation-as-failure. If A fails, not A succeeds, otherwise fails.
once
If A fails, once A fails. Otherwise, succeed once.
choose
Procedural conditional.
choose(A) B else C;
- If once A succeeds, evaluates B, otherwise evaluate C.
cut
Prolog's cut.