From 674bce8c96309ae7c38a7e2b946f3f18430a0b00 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 9 Jul 2024 16:14:23 +0200 Subject: Support static-local variables --- README | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'README') diff --git a/README b/README index a8f0b7c..f30fdb1 100644 --- a/README +++ b/README @@ -168,3 +168,19 @@ The build script also accepts some subcommands. They are as follows: ((x)) = x*10 + y; /* legal */ (true ? x : y) = x*10 + y; /* illegal */ + +10. Static local variables allow for block-scoped global variables. This + is useful for having function state persist across multiple calls. + + iota :: () int { + static x := -1; + x = x + 1; + return x; + } + + pub main :: () { + zero := iota(); + one := iota(); + two := iota(); + three := iota(); + } -- cgit v1.2.3