Open jorolf opened 6 years ago
We are also going to include other affixes like suffix
and prefix
this would enable us to also define unary operators:
prefix fn dispose(...) {
thing.dispose();
}
dispose [...];
We are also going to split out these functions to normal functions (fn
) and operators (op
).
The difference would be that operators must have special character names (e.g. *+-/$><) and affix funtions need to be seperated by spaces when being used
infix op -(a: i32, b: i32) { a-b } //pointless but get's the point across
infix fn minus(a: i32, b: i32) { a-b }
a-b
: possible
a - b
: possible as well
a minus b
: possible
aminusb
: not possible -> ambiguous is it minus(a, b) or the variable aminusb
Affix operator ambiguity:
Code | Result |
---|---|
a* -b |
Syntax error, two expressions a* and -b |
a *-b |
Syntax error, two expressions a and *-b |
a*- b |
Syntax error, two expressions a*- and b |
a*-b |
Syntax error |
a * - b |
Syntax error |
a* - b |
Infix operator - with operands a* and b |
a * -b |
Infix operator * with operands a and -b |
a *- b |
Infix operator *- with operands a and b |
we do need to handel precedence
@precedence(0)
smaller numbers takes precedence
Instead of allowing user to use operator overloading we should allow infix funtions.
Infix are funtions that take two parameters and are marked with
infix
. They can be used like this:the declaration would look something like this:
possible usages would be operator overloading:
or ranges: