Category:Elena: Difference between revisions

Line 67:
The assigning value can be an expression itself:
 
public program =
[
console writeLine("Hello!"); writeLine("How are you?").
Line 75:
ELENA is a dynamic language and in normal case we may not specify the variable type:
 
public program =
[
var s := "Hello".
Line 91:
But it is still possible to specify the variable expected type:
 
typeT<LiteralValue> s := "Hello".
console writeLine(s).
 
Line 104:
 
literal s := "Hello".
s := T<literal>(2).
 
Why? ELENA is a dynamic language and in most cases resolves the types in run-time. So our code will be actually
Line 110:
 
literal s := "Hello".
s := 2 T<literal.>(2)
 
It is guaranteed that the result of literalthe cast message is an instance of LiteralValue, so if the object supports the message the conversion will be done quietly. In fact this code will work because IntNumber supports this conversion. But the following code will be broken in run-time:
 
int n := 3.
n := 3.4r.
 
The output will be:
Anonymous user