-
Notifications
You must be signed in to change notification settings - Fork 0
function
Functions can be defined in the following natural ways:
function square (n: number){ n*n }
to square a number: return it * it
square of a number = it * it
square(number n)=n*n
square(n)=n*n
square:=it*it
The parser should differentiate between variables and functions via these heuristics:
- functions have braces left of the assignment
square(n)=n*nor - functions have blocks right of the assignment
square = {it*it}or - functions use
:=for the assignmentsquare:=it*it
The difference to square=it*it is that variables get evaluated instantly and only once, whereas
The function square:=it*it is a dangling closure
Under the hood all are represented equally: as the charged data
square = {it*it}
Together with an entry in the pattern dictionary [:square, number] => &square denoting that the symbol 'square' together with the type number should be resolved to the function square.
Functions are unary prefix operators, that is in an expression
a f b c they get parsed as a (f (b c))
Every function generates a suffix operator: square 2 == 2 squared
The suffix word is the function name plus d or ed (squared, sorted) for any function taking an argument.
An ungrouped mix with arithmetic, 1+2 squared, is ambiguous: the compiler asks whether it means 1+(2 squared) or
(1+2) squared (user, 2026-10-03); unanswered it is an error naming both forms. 2 squared+1 is (2 squared)+1.