-
Notifications
You must be signed in to change notification settings - Fork 1
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
146 changed files
with
1,423 additions
and
1,155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
fun hmm(): | ||
fun hmm() { | ||
let a, _ = (1, 0) | ||
fun capture(): a + 1 | ||
fun capture() {a + 1} | ||
capture | ||
} | ||
|
||
let _, _ = (copy(hmm), 0) | ||
|
||
fun hmm_move(): | ||
fun hmm_move() { | ||
let a, _ = (1, 0) | ||
-- a is not explicitly copied, thus moved | ||
fun capture(): a + 1 | ||
fun capture() {a + 1} | ||
capture | ||
} | ||
|
||
let _, _ = (copy(hmm_move), 0) | ||
|
||
fun test(): | ||
fun test() { | ||
let a = ["hello"] | ||
fun () [a]: println(a.[0]) | ||
fun () [a] {println(a.[0])} | ||
} | ||
|
||
let c = test() | ||
copy(c)() |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
let a = ["aoeu"] | ||
let b& = "aoeu" | ||
string/modify_buf(&b, fun(arr&): | ||
__unsafe_ptr_set(&array/data(arr), 1, !'i')) | ||
string/modify_buf(&b, fun(arr&) { | ||
__unsafe_ptr_set(&array/data(arr), 1, !'i') | ||
}) | ||
println(b) | ||
println("aoeu") | ||
println(a.[0]) |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
let a = #some(("thing", 0)) | ||
|
||
match copy(a): | ||
match copy(a) { | ||
#some((t, _)): println(t) | ||
#none: () | ||
} |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
fun return_closure(name): | ||
fun return_closure(name) { | ||
-- create object on heap | ||
let n = fmt("++", name) | ||
fun (): println(n) | ||
fun () {println(n)} | ||
} | ||
|
||
let f = return_closure("aoeu") | ||
f() |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
let data& = array/create(16) | ||
|
||
iter_range(0, 10, fun i: | ||
array/push(&data, !fun () [i]: println(fmt("on iteration: ", i)))) | ||
iter_range(0, 10, fun i { | ||
array/push(&data, !fun () [i] {println(fmt("on iteration: ", i))}) | ||
}) | ||
|
||
array/iter(data, fun f: f()) | ||
array/iter(data, fun f {f()}) |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
fun rec fib(n): | ||
if n < 2: n | ||
else: fib(n - 1) + fib(n - 2) | ||
fun rec fib(n) { | ||
if n < 2 {n} | ||
else {fib(n - 1) + fib(n - 2)} | ||
} | ||
|
||
println(fmt(fib(30))) |
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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
external printi : (int) -> unit | ||
|
||
fun apply(x, f): f(x) | ||
fun apply(x, f) {f(x)} | ||
|
||
fun add1(x): x + 1 | ||
fun add1(x) {x + 1} | ||
|
||
-- We also pass polymorphic functions | ||
fun pass(x): copy(x) | ||
fun pass(x) {copy(x)} | ||
|
||
-- ..and a lambda | ||
let pass2 = fun x: copy(x) | ||
let pass2 = fun x {copy(x)} | ||
|
||
fun makefalse(b): | ||
if b: false else: b | ||
fun makefalse(b) { | ||
if b {false} else {b} | ||
} | ||
|
||
fun int_of_bool(b): if b: 1 else: 0 | ||
fun int_of_bool(b) {if b {1} else {0}} | ||
|
||
-- TODO polymorphic recursion example | ||
|
||
apply(0, add1).printi() | ||
apply(1, fun x: x + 1).printi() | ||
apply(1, fun x {x + 1}).printi() | ||
true.apply(makefalse).int_of_bool().printi() | ||
printi(apply(3, fun x: copy(x))) | ||
printi(apply(3, fun x {copy(x)})) | ||
printi(apply(4, pass)) | ||
printi(apply(5, pass2)) |
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
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
external printi : (int) -> unit | ||
|
||
fun rec foo(i): | ||
if i < 2: printi(i - 1) | ||
else: | ||
if i < 400: printi(i) | ||
else: printi(i + 1) | ||
fun rec foo(i) { | ||
if i < 2 {printi(i - 1)} | ||
else { | ||
if i < 400 {printi(i)} | ||
else {printi(i + 1)} | ||
foo(i - 1) | ||
|
||
} | ||
} | ||
foo(4) |
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
fun rec a(k, x1, x2, x3, x4, x5): | ||
if k <= 0: | ||
fun rec a(k, x1, x2, x3, x4, x5) { | ||
if k <= 0 { | ||
x4() + x5() | ||
else: | ||
} else { | ||
let m& = !k | ||
fun rec b(): | ||
fun rec b() { | ||
&m = m - 1 | ||
a(m, b, x1, x2, x3, x4) | ||
} | ||
b () | ||
} | ||
} | ||
|
||
a(10, fun (): 1, fun (): -1, fun (): -1, fun (): 1, fun (): 0).fmt().println() | ||
a(10, fun () {1}, fun () {-1}, fun () {-1}, fun () {1}, fun () {0}).fmt().println() |
Oops, something went wrong.