-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Simple array | ||
let simple_array = [1, "Axolotl", 2.3]; | ||
print(simple_array[1]); | ||
simple_array[1] = "Gods"; | ||
array_push(simple_array, 42); | ||
print(array_length(simple_array)); | ||
|
||
// Arrays may contain any expression | ||
let complex_array = [ | ||
func() { | ||
2 + 3 | ||
}, | ||
42, | ||
3.4, | ||
[ | ||
"Another array" | ||
], | ||
{ | ||
"my_key": 5 | ||
} | ||
]; | ||
|
||
// Hashes contain key-value-pairs | ||
let my_hash = { | ||
"my_func": func(a) { | ||
a + 7 | ||
}, | ||
"number": 23 | ||
}; | ||
|
||
print(my_hash["my_func"](my_hash["number"])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Simple function | ||
let add = func(a, b) { | ||
return a + b; | ||
}; | ||
|
||
print(add(1, 2)); | ||
|
||
// Implicit returns are supported | ||
let add_impl = func(a, b) { | ||
a + b | ||
}; | ||
|
||
print(add_impl(1, 2)); | ||
|
||
// Functions are expressions | ||
func(name) { | ||
print("Hello, my name is " . name); | ||
}("Senk Ju"); | ||
|
||
let func_arr = [ | ||
func() { | ||
return "Axolotl"; | ||
} | ||
]; | ||
|
||
print(func_arr[0]()); | ||
|
||
// Closures are supported | ||
let my_closure = func() { | ||
let name = "Senk Ju"; | ||
|
||
let print_name = func() { | ||
print("Hello, my name is " . name); | ||
}; | ||
|
||
print_name(); | ||
}; | ||
|
||
my_closure(); |