-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Structs cannot be tested for equality with
==
or !=
.
- Loading branch information
Showing
9 changed files
with
64 additions
and
75 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
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 @@ | ||
struct list { | ||
value: string; | ||
next: list|void; | ||
} | ||
|
||
fun empty() { | ||
return null as list|void | ||
} | ||
|
||
fun cons(v: string, l: list|void) { | ||
make list(value:v, next:l) as list|void | ||
} | ||
|
||
equal_list : list|void, list|void -> boolean | ||
fun equal_list(a: list|void, b: list|void) { | ||
typecase a is void { | ||
typecase b is void { | ||
return true | ||
} | ||
} | ||
typecase a is list { | ||
typecase b is list { | ||
return a.value == b.value and equal_list(a.next, b.next) | ||
} | ||
} | ||
return false | ||
} | ||
|
||
main = fun() { | ||
l1 = cons("first", cons("second", cons("third", empty()))); | ||
l2 = cons("first", cons("second", cons("third", empty()))); | ||
l3 = cons("first", cons("second", empty())); | ||
|
||
if (equal_list(l1, l2) and not equal_list(l2, l3)) { | ||
print("Yep, story checks out") | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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