From 2e0eeeed63308e004e882f74a6077bc0fb3352bc Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sat, 18 Jan 2025 12:16:00 +0100 Subject: Examples: Add variable scopes example --- examples/5.src | 13 +++++++++---- examples/6.src | 8 ++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 examples/6.src diff --git a/examples/5.src b/examples/5.src index 573ee6a..d9a8dad 100644 --- a/examples/5.src +++ b/examples/5.src @@ -1,8 +1,13 @@ -let print_input = (input) => { - print(input); - return input; +let foo = () => { + let x = 1; + print(x); + return x; }; let main = () => { - return print_input(7); + let x = 2; + /* As you see, the language supports variable scopes */ + foo(); + print(x); + return x; }; diff --git a/examples/6.src b/examples/6.src new file mode 100644 index 0000000..573ee6a --- /dev/null +++ b/examples/6.src @@ -0,0 +1,8 @@ +let print_input = (input) => { + print(input); + return input; +}; + +let main = () => { + return print_input(7); +}; -- cgit 1.4.1