Skip to content

Commit

Permalink
Add case syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Aug 14, 2023
1 parent 2ea6f88 commit 22a8725
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion auto_editor/lang/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ def syn_case(env: Env, node: list) -> Any:
raise MyError("case: bad syntax")
if type(case_clause[0]) == list:
for case in case_clause[0]:
if is_equal(my_eval(env, case), val_expr):
if is_equal(case, val_expr):
return my_eval(env, case_clause[1])
elif type(case_clause[0]) == Sym and case_clause[0].val == "else":
return my_eval(env, case_clause[1])
Expand Down
5 changes: 3 additions & 2 deletions auto_editor/subcommands/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,9 @@ def cases(*cases: tuple[str, Any]) -> None:
)

def palet_scripts():
run.raw(["palet", "resources/scripts/maxcut.pt"])
run.raw(["palet", "resources/scripts/scope.pt"])
run.raw(["palet", "resources/scripts/maxcut.pal"])
run.raw(["palet", "resources/scripts/scope.pal"])
run.raw(["palet", "resources/scripts/case.pal"])

tests = []

Expand Down
6 changes: 6 additions & 0 deletions resources/scripts/case.pal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env auto-editor palet

(assert (equal? (case (+ 7 5) [(1 2 3) 'small] [(10 11 12) 'big]) 'big))
(assert (equal? (case (- 7 5) [(1 2 3) 'small] [(10 11 12) 'big]) 'small))
(assert (case (mod 3 2) [(0) #f] [else #t]))
(assert (case 'y [(y) #t]))
File renamed without changes.
File renamed without changes.

0 comments on commit 22a8725

Please sign in to comment.