Message declaration
Type name = body
- declarationobj name
- call
Cheat Sheet
Unary
Declarations and calls always have same signature.
The only difference is that Declarations use type names and calls use instances of these types.
New messages can be declared for any types, custom or internal like Int.
With body
When there you need many statements use square brackets:
Return type
-> Type
is used to declare return type
If its not declared it will be inferred.
Keyword
Local arg names
If the key is not well suited for the name of a local variable, there is a syntax for declaring a separate name for them.
Single expression form
If the method body consists of a single expression, then you can do without a block of code:
With short form you can omit the return type(-> Int
) and return statement(^
)
this
this
is an implicit argument of any method representing a receiver
Try to run this example niva filename.niva
There is also syntax sugar, just .
can be used instead of this
Fields
All the fields of the type are added in to scope of the method
extend
Syntax sugar to declare many messages for the same type
Binary
I would not recommend to create a custom binary messages(i.e. operator overloading), usually keyword message with one arg is more readable.
But here are rare cases when its really suits, for example for some DSL purposes.
here we have 5 message calls, 3 unary d
m
y
and 2 binary /
between them.
Since unary always evals first it is possible to create such DSL for dates. Same for file path, for example message like
Could create a path with proper delimiters(/
on Unix and \
on Windows)
And ofc its not possible to overide the defaults operators like Int + Int