-
Notifications
You must be signed in to change notification settings - Fork 10
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
smaludzi
committed
Mar 23, 2020
1 parent
cdc8ef4
commit 315c4cf
Showing
14 changed files
with
298 additions
and
23 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 |
---|---|---|
|
@@ -16,7 +16,8 @@ func main() -> int | |
} | ||
else | ||
{ | ||
print(90) | ||
print(90); | ||
assert(0) | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ func main() -> int | |
{ | ||
let o = Optional::Some(10); | ||
|
||
print(getF(o)()); | ||
assert(getF(o)() == 10); | ||
|
||
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
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,24 @@ | ||
|
||
enum Result { Ok { value : int; }, Err { msg : string; } } | ||
|
||
func calc() -> Result | ||
{ | ||
Result::Ok(1) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = if let (Result::Ok = calc()) | ||
{ | ||
200 | ||
} | ||
else | ||
{ | ||
90 | ||
}; | ||
|
||
assert(i == 200); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
enum Result { Ok { value : int; }, Err { msg : string; } } | ||
|
||
func calc() -> Result | ||
{ | ||
Result::Ok(1) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = match calc() | ||
{ | ||
Result::Ok -> 200; | ||
Result::Err -> 90; | ||
}; | ||
|
||
assert(i == 200); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
enum Result { Ok { value : int; }, Err { msg : string; } } | ||
|
||
func calc() -> Result | ||
{ | ||
Result::Ok(200) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = match calc() | ||
{ | ||
Result::Ok(value) -> value; | ||
Result::Err(msg) -> 90; | ||
}; | ||
|
||
assert(i == 200); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
enum Result { Ok { value : int; }, Err { msg : string; } } | ||
|
||
func calc() -> Result | ||
{ | ||
Result::Ok(200) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = if let (Result::Ok(value) = calc()) | ||
{ | ||
value | ||
} | ||
else | ||
{ | ||
90 | ||
}; | ||
|
||
assert(i == 200); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
record Rect | ||
{ | ||
x : int; | ||
y : int; | ||
} | ||
|
||
enum Result { Ok { value : Rect; }, Err { msg : string; } } | ||
|
||
func printRect(r : Rect) -> string | ||
{ | ||
prints("x " + r.x + " y " + r.y + "\n") | ||
} | ||
|
||
func rect() -> Result | ||
{ | ||
Result::Ok(Rect(200, 300)) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = if let (Result::Ok(rect) = rect()) | ||
{ | ||
printRect(rect); | ||
rect.x + rect.y | ||
} | ||
else | ||
{ | ||
90 | ||
}; | ||
|
||
assert(i == 500); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
record Rect | ||
{ | ||
x : int; | ||
y : int; | ||
printRect(r : Rect) -> string; | ||
} | ||
|
||
enum Result { Ok { value : Rect; }, Err { msg : string; } } | ||
|
||
func printRect(r : Rect) -> string | ||
{ | ||
prints("x " + r.x + " y " + r.y + "\n") | ||
} | ||
|
||
func rect() -> Result | ||
{ | ||
Result::Ok(Rect(200, 300, printRect)) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = if let (Result::Ok(rect) = rect()) | ||
{ | ||
rect.printRect(rect); | ||
rect.x + rect.y | ||
} | ||
else | ||
{ | ||
90 | ||
}; | ||
|
||
assert(i == 500); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
record Arr | ||
{ | ||
arr[D] : string; | ||
} | ||
|
||
enum Result { Ok { value : Arr; }, Err { msg : string; } } | ||
|
||
func printArr(arr[D] : string) -> int | ||
{ | ||
let i = 0; | ||
|
||
for (i = 0; i < D; i = i + 1) | ||
{ | ||
prints(arr[i] + "\n") | ||
}; | ||
|
||
0 | ||
} | ||
|
||
func arr() -> Result | ||
{ | ||
Result::Ok(Arr(["one", "two", "three", "four"] : string)) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = if let (Result::Ok(value) = arr()) | ||
{ | ||
printArr(value.arr); | ||
1 | ||
} | ||
else | ||
{ | ||
0 | ||
}; | ||
|
||
assert(i == 1); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
record Rect | ||
{ | ||
x : int; | ||
y : int; | ||
} | ||
|
||
enum Result { Ok { rects[D] : Rect; }, Err { msg : string; } } | ||
|
||
func printRect(rects[D] : Rect) -> int | ||
{ | ||
let i = 0; | ||
|
||
for (i = 0; i < D; i = i + 1) | ||
{ | ||
prints(rects[i].x + " " + rects[i].y + "\n") | ||
}; | ||
|
||
0 | ||
} | ||
|
||
func rects() -> Result | ||
{ | ||
Result::Ok([Rect(100, 200), Rect(200, 300), Rect(300, 400)] : Rect) | ||
} | ||
|
||
func main() -> int | ||
{ | ||
let i = 0; | ||
let j = if let (Result::Ok(rects) = rects()) | ||
{ | ||
printRect(rects); | ||
1 | ||
} | ||
else | ||
{ | ||
0 | ||
}; | ||
|
||
assert(j == 1); | ||
|
||
0 | ||
} | ||
|
Oops, something went wrong.