Skip to content

Commit

Permalink
Fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vkobinski committed Jun 29, 2024
1 parent 30a97f4 commit 01f00ca
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/benda/src/benda_ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn run(book: &Book) -> Option<(Term, String, Diagnostics)> {
let args = None;

bend::run_book(
book.clone(),
book.to_owned(),
run_opts,
compile_opts,
diagnostics_cfg,
Expand Down
15 changes: 14 additions & 1 deletion examples/insertion_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ def random(n):
else:
return (random(n - 1) * 16 + 101387) % 429453

def print_list(list):
print("[", end="")
while True:
match list:
case book.adts.List.tCons(value, tail):
print(value, end=", ")
list = tail
case book.adts.List.tNil():
break
print("]")


def main():
data = rnd(10)

result = book.defs.insertion_sort(data)
print("Result: ", result.to_adt(book.adts.List))
sorted = result.to_adt(book.adts.List)
print("Result: ", end="")
print_list(sorted)


if __name__ == "__main__":
Expand Down
23 changes: 20 additions & 3 deletions examples/quicksort.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,20 @@ def from_cons_list(xs) -> list[u24]:
result.append(value)
xs = tail

def print_list(list):
print("[", end="")
while True:
match list:
case book.adts.List.tCons(value, tail):
print(value, end=", ")
list = tail
case book.adts.List.tNil():
break
print("]")


def main():
data = gen_list(10, 1000)
data = gen_list(5, 1000)
print("Data: ", data)

expected = sorted(data)
Expand All @@ -71,8 +83,13 @@ def main():

sorted_res = book.defs.Sort(cons_list)
sorted_arr = sorted_res.to_adt(book.adts.List)
print("Result: ", sorted_arr)
print("Sum: ", book.defs.Sum(sorted_res))

sum = book.defs.Sum(sorted_res)


print("Result: ", end="")
print_list(sorted_arr)
print("Sum: ", sum)

#mocked_sorted = mock_sort(cons_list)
#mocked_sorted_arr = mocked_from_cons_list(mocked_sorted)
Expand Down

0 comments on commit 01f00ca

Please sign in to comment.