Extension:Expressions

The Expressions extension enhances the wikitext parser with boolean algebra.

Usage
This extension introduces the parser function #expression. It evaluates a boolean expression and returns one of two strings depending on the result:



The available operators are listed on the right, in order of precedence.

The extension makes use of type juggling. Therefore, non-empty strings are converted to, zero is converted to  , et cetera:


 * → 1
 * → 1
 * → 1
 * → 1
 * → 1

Two values can be compared before type juggling using the  operator:


 * → 1
 * → 0
 * → 0

You can read more about type juggling here.

Associativity
All operators in this extension, except from the unary operators, are left-associative. This means the left part of the expression will be evaluated first:


 * →  → 1
 * →  → 0

This might not be what you expect at first, therefore it is important to keep it in mind.

Negative numbers
Numbers can be converted to a negative number using the  (minus) operand as you would expect. This is the only operator that requires it operand to be a number, and not a string or boolean. If something other than a number is given, the parser will give an error:

I got stuck at the following expression:

1| -true ^ I was expecting to see an number, but instead I got a 'boolean'.