Skip to content

Commit f1178cd

Browse files
committed
[add] an example for blocks.
1 parent 4fbf6dd commit f1178cd

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This language is still currently experimental with many more features to come.
2323
* [Loops](examples/loops.ls).
2424
* [Closures](examples/closure.ls).
2525
* [Recursion](examples/recursion.ls).
26-
* Blocks.
26+
* [Blocks](examples/blocks.ls).
2727
* Printing.
2828
* Lambda expressions/Anonymous functions.
2929
* Static & Instance getters.

examples/blocks.ls

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Blocks allow variables to create isolated scopes from one another, allowing
2+
// var to be reused for variables with the same name.
3+
4+
{
5+
var x = 10;
6+
print x;
7+
}
8+
9+
{
10+
var x = "I'm in my own scope!";
11+
print x;
12+
}

examples/closure.ls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ func Closure() {
1414
// Gets a function from the closure back.
1515
var counter = Closure();
1616

17-
// Calling counter() increments the counter.
17+
// Calling counter() increments the counter contained within the closure.
1818
print counter();
1919
print counter();

0 commit comments

Comments
 (0)