Function
Function mean a produce in program. But lots languages didn't realize this true.
I am talking about user defined operation. Traditional, we will use function like add(1, 3)
.
But what we need is 1 + 3
.
In fact we also need dynamic operator. No one can expected every operator could need.
So in elz. You will use fn
to represent operator.
For example:
fn +(lv: str, rv: str) -> str {
return strings.concat(lv, rv);
}
Ok, It seems good. But not enough. In this case, the problem is how do we make sure it's a function or operator?
In scala, it's answer is operator equal function. It seems good, theory complete, but useless.
You have a very very very low opportunity write done a code say store writeTo data
. Just because you define a function like
fn writeTo(store: Store, data: Any) {
// Write data into store
}
It doesn't make sense, right?
And you might not want +(1, 3)
just because it can.
So. we have to give it a answer, and the answer in elz is @annotation.
You add @operator annotation before fn
keyword.
@operator
fn +(lv: data, rv: data) -> data { ... }
@operator
's meaning change by mount of parameter.
1 => @op expr
2 => expr @op expr
I not decide how to deal with three yet.
Where can user use user define operator?
If return value, then it can be invoke as statement and expression place.
If no, than it can only invoke as statement.