Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
46
Task/Variables/Dyalect/variables.dyalect
Normal file
46
Task/Variables/Dyalect/variables.dyalect
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//A constant declaration
|
||||
let pi = 3.14
|
||||
|
||||
private {
|
||||
//private constant, not visible outside of a module
|
||||
let privateConst = 3.3
|
||||
}
|
||||
|
||||
//Variable declaration
|
||||
var x = 42
|
||||
|
||||
//Assignment
|
||||
x = 42.42
|
||||
|
||||
//Dyalect is a dynamic language, so types are attached
|
||||
//to values, not to the names
|
||||
var foo = (x: 2, y: 4) //foo is of type Tuple
|
||||
var bar = "Hello!" //bar is of type String
|
||||
|
||||
//Global variable
|
||||
var g = 1.1
|
||||
|
||||
{
|
||||
//local variable (not visible outside of { } brackets)
|
||||
var loc = 2.2
|
||||
}
|
||||
|
||||
func fun() {
|
||||
//Local variables, not visible outside of function
|
||||
var x = 1
|
||||
var y = 2
|
||||
}
|
||||
|
||||
func parent() {
|
||||
//A local variable inside a parent function
|
||||
var x = 1
|
||||
func child() {
|
||||
//A local variable inside a nested function
|
||||
//It shadows a parent's variable
|
||||
var x = 2
|
||||
|
||||
//But this is how we can reference a variable from
|
||||
//a parent function
|
||||
base.x
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue