Operators

Calling Syntax and Precedence #

Mathematical operators and functions in general rely on prefix notation. By doing this, it is possible to call and compose operations with a minimum of explicit grouping. When all operators and functions have known arity, no grouping markers are necessary. In cases where operators have variable arity, the operation is closed with MKAY. An MKAY may be omitted if it coincides with the end of the line/statement, in which case the EOL stands in for as many MKAYs as there are open variadic functions.

Calling unary operators then has the following syntax:

<operator> <expression1>

The AN keyword can optionally be used to separate arguments, so a binary operator expression has the following syntax:

<operator> <expression1> [AN] <expression2>

An expression containing an operator with infinite arity can then be expressed with the following syntax:

<operator> <expr1> [[[AN] <expr2>] [AN] <expr3> ...] MKAY

Math #

The basic math operators are binary prefix operators.

SUM OF <x> AN <y>       BTW +
DIFF OF <x> AN <y>      BTW -
PRODUKT OF <x> AN <y>   BTW *
QUOSHUNT OF <x> AN <y>  BTW /
MOD OF <x> AN <y>       BTW modulo
BIGGR OF <x> AN <y>     BTW max
SMALLR OF <x> AN <y>    BTW min

<x> and <y> may each be expressions in the above, so mathematical operators can be nested and grouped indefinitely.

Math is performed as integer math in the presence of two NUMBRs, but if either of the expressions are NUMBARs, then floating point math takes over.

If one or both arguments are a YARN, they get interpreted as NUMBARs if the YARN has a decimal point, and NUMBRs otherwise, then execution proceeds as above.

If one or another of the arguments cannot be safely cast to a numerical type, then it fails with an error.

Boolean #

Boolean operators working on TROOFs are as follows:

BOTH OF <x> [AN] <y>          BTW and: WIN iff x=WIN, y=WIN
EITHER OF <x> [AN] <y>        BTW or: FAIL iff x=FAIL, y=FAIL
WON OF <x> [AN] <y>           BTW xor: FAIL if x=y
NOT <x>                       BTW unary negation: WIN if x=FAIL
ALL OF <x> [AN] <y> ... MKAY  BTW infinite arity AND
ANY OF <x> [AN] <y> ... MKAY  BTW infinite arity OR

<x> and <y> in the expression syntaxes above are automatically cast as TROOF values if they are not already so.

Comparison #

Comparison is (currently) done with two binary equality operators:

BOTH SAEM <x> [AN] <y>   BTW WIN iff x == y
DIFFRINT <x> [AN] <y>    BTW WIN iff x != y

Comparisons are performed as integer math in the presence of two NUMBRs, but if either of the expressions are NUMBARs, then floating point math takes over. Otherwise, there is no automatic casting in the equality, so BOTH SAEM "3" AN 3 is FAIL.

There are (currently) no special numerical comparison operators. Greater-than and similar comparisons are done idiomatically using the minimum and maximum operators.

BOTH SAEM <x> AN BIGGR OF <x> AN <y>   BTW x >= y
BOTH SAEM <x> AN SMALLR OF <x> AN <y>  BTW x <= y
DIFFRINT <x> AN SMALLR OF <x> AN <y>   BTW x > y
DIFFRINT <x> AN BIGGR OF <x> AN <y>    BTW x < y

If <x> in the above formulations is too verbose or difficult to compute, don’t forget the automatically created IT temporary variable. A further idiom could then be:

<expression>, DIFFRINT IT AN SMALLR OF IT AN <y>

Suggestions are being accepted for coherently and convincingly english-like prefix operator names for greater-than and similar operators.

Concatenation #

An indefinite number of YARNs may be explicitly concatenated with the SMOOSH...MKAY operator. Arguments may optionally be separated with AN. As the SMOOSH expects strings as its input arguments, it will implicitly cast all input values of other types to YARNs. The line ending may safely implicitly close the SMOOSH operator without needing an MKAY.

Casting #

Operators that work on specific types implicitly cast parameter values of other types. If the value cannot be safely cast, then it results in an error.

An expression’s value may be explicitly cast with the binary MAEK operator.

MAEK <expression> [A] <type>

Where <type> is one of TROOF, YARN, NUMBR, NUMBAR, or NOOB. This is only for local casting: only the resultant value is cast, not the underlying variable(s), if any.

To explicitly re-cast a variable, you may create a normal assignment statement with the MAEK operator, or use a casting assignment statement as follows:

<variable> IS NOW A <type>         BTW equivalent to
<variable> R MAEK <variable> [A] <type>

Edit this page   Add a New Page