I thought there was no static key word and is lack of its features as like c family languages have. I was wrong.
BTW,besides desctructuring tuple into multiple variables,struct fields values can also be destructured into mutliple variables .
Maybe it is good to add it into the doc,esp. features behave differently comparing to other languages which have the same [key words]|usage.It will take lots of time to exam features one by one by coding piece by piece.
fn counter() ->int {
static let count:int;
return ++count;
}
fn main() {
counter();
counter();
println "{counter()}";
}
running result:
E:\Learning\zenpack\ex>zc run static01.zc
Compiling static01.zc...
Running static01.exe
3
E:\Learning\zenpack\ex>
import "std.zc";
test "let usage"{
let a=21;
let b:f32=3.14;
let (c,d)=(1,2);
let Point{x,y}=Point{x:1,y:2};
"a={a}\tb={b}\tc={c}\td={d}\nx={x}\ty={y}";
}
struct Point{
x: int;
y: int;
}
test "more let usage"{
let some_value=Option<int>::Some(3);
let Some(z)=some_value else{
return;
}
"z={z}";
let (x,_,y)=(1,2,3)
"x={x},y={y}";
}
I thought there was no
statickey word and is lack of its features as like c family languages have. I was wrong.BTW,besides desctructuring tuple into multiple variables,struct fields values can also be destructured into mutliple variables .
Maybe it is good to add it into the doc,esp. features behave differently comparing to other languages which have the same [key words]|usage.It will take lots of time to exam features one by one by coding piece by piece.
running result: