Skip to content

operator

pannous edited this page Jul 4, 2022 · 18 revisions

Functions group externally square 1 + 2 == square(1 + 2) VS √4+5=√(4)+5 Operators group tighter than functions

Functions expect their arguments on the right hand side
Suffix operators expect their arguments on the left-hand side e.g. ²=square
Infix operators expect their arguments on both side: x+y x*y ...
Prefix operators expect their arguments on the right-hand side -x, ++x, !x, ½x
Circumfix operators are such as (...) {...} "..." are all built in and not overwritable todo
N-ary operators are currently not supported ( x = 5 % 7 todo: because they can be rewritten x%7==5 ? )

General N-ary operators are currently not supported ( e.g. mathematical equals-with-respect-to x == y % z todo: because they can be rewritten x%z==y%z ? ) Special hardwired ternary operators: array#position=value, list[index]=value, data[pattern]=value, condition?then:else The first cases can be handled via references

UTF symbols and their english aliases are almost completely identical when parsing and evaluating 1 + 2 == 1 plus 2 == 1 add 2

goals

Operators follow an alias hierarchy, so a & b will try to invoke et, and, add and may even fallback to plus combine concat, or let the compiler suggest such fallbacks if the functions are not implemented on the object.

List of operators and their variants (see aliases.wasp):

* et &
* and && ⋀ ∧
* or || ⋁ ∨ 
* xor ^| ⊻
* not ! ¬
* add +
* plus +
* minus subtract sub -
* times mul * × ⋅ multiply
* div / ÷
* mod modulo %
* equal equals ≟ == ≡ ﹦ 
* similar circa ~ ⋍ ≈ ~~ approximately
* more bigger >
* less smaller <
* exp / to the power ^
* square_root √ sqrt
* increase ++ 
* increase … by  +=
* reduce --
* reduce … by  -=
* divide … by  /=
* to … / … be :=  
* to-the ^
* be :=
* is := or == or instance
* then pipe |
* of in @
* 's with .
* that / with / which / filter []
* index nr 1st 2nd 3rd 4th nth _th #
* xor ⊻ ^|
* nand ¬&

Caution: ^ in Angle is power “to the”, xor is ^| ⊻

Note: bitwise operators & | are also allowed for truthyness comparisons

However the english variants or mathematical signs are usually prefered.

Keywords that resolve to operators depending on context:

is in of to from sub super

The '=' operator is context sensitive: usually it acts as assignment like :=, in conditions it acts as comparison like

Operators are usually pure meaning that they are side effects free and do not use global information.

Operators can be self modifying, such as ++, += and << as in

cout << "Hello" << " " << "world!" << endl;

control flow keywords

if then else otherwise once when times try catch except while until unless

Infix operators

Infix operators in Angle (as in Julia) are simply functions that can be used with an alternative syntax.

Operator overloading

The behavior of operators can be documented or changed by declaring either the symbol or the name to add a tree to an image: paint tree on image
tree + image := paint tree on image

All Operators automatically receive a self modifying variant: x ⊛= b is always a shorthand for x = x ⊛ b for all custom operators (⊛ here being a wildcard placeholder).

Introducing a new operator changes the lexical specification of the language, which changes the lexical analysis. The arity and precedence of the operator is then part of the phrase syntax of the language, which changes the phrase-level analysis. For example, adding an operator @ requires lexing and tokenizing this character, and the phrase structure ( syntax tree) depends on the arity and precedence of this operator.

Functions group externally: square 1 + 2 == square(1 + 2) VS √4+5=√(4)+5 Operators group tighter than functions

prefix operator ⁻ := it*-1
suffix operator ⁰ := 1
suffix operator ³ := it*it*it

Note that suffix operators correspond to (prefix) functions:

x² = square x 

Note that suffix operators correspond to (suffix) language concious functions: x² = x squared

squared is recognized as grammatical form of the 'square' function.

This simple pattern holds for all functions:

x == x d


See k programming language
https://estradajke.github.io/k9-simples/k9/index.html
https://news.ycombinator.com/item?id=28493283

# superscript signs bind higher! `x²⁺³ == x⁵` 

Home

Philosophy

data & code blocks

features

inventions

evaluation

keywords

iteration

tasks

examples

todo : bad ideas and open questions

⚠️ specification and progress are out of sync

Clone this wiki locally