Skip to content

Commit

Permalink
Fix quoted slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Sep 25, 2023
1 parent c246f86 commit ce43937
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
7 changes: 3 additions & 4 deletions auto_editor/lang/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ def syn_class(env: Env, node: list) -> Any:
def attr(env: Env, node: list) -> Any:
guard_term(node, 3, 3)

if not isinstance(node[2], Sym):
if type(node[2]) is not Sym:
raise MyError("@r: attribute must be an identifier")

return my_eval(env, [node[2], node[1]])
Expand All @@ -1318,10 +1318,9 @@ def my_eval(env: Env, node: object) -> Any:
raise MyError("Can't use edit methods if there's no input files")
return edit_method(node.val, env["@filesetup"], env)

if isinstance(node, list):
if type(node) is list:
if not node:
raise MyError("Illegal () expression")

if node[0] is list: # Handle vector literal
return [my_eval(env, item) for item in node[1]]

Expand Down Expand Up @@ -1394,7 +1393,7 @@ def my_eval(env: Env, node: object) -> Any:
"symbol?": (is_symbol := Contract("symbol?", lambda v: type(v) is Sym)),
"string?": is_str,
"char?": (is_char := Contract("char?", lambda v: type(v) is Char)),
"vector?": (is_vector := Contract("vector?", lambda v: isinstance(v, list))),
"vector?": (is_vector := Contract("vector?", lambda v: type(v) is list)),
"array?": (is_array := Contract("array?", lambda v: isinstance(v, np.ndarray))),
"bool-array?": is_boolarr,
"range?": (is_range := Contract("range?", lambda v: type(v) is range)),
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/lib/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def lt_c(n: int | float | Fraction) -> Proc:
return Proc(f"(</c {n})", lambda i: i < n, (1, 1), [is_real])


def between_c(n: int | float | Fraction, m: int | float | Fraction) -> Proc:
def between_c(n: Any, m: Any) -> Proc:
if m > n:
return Proc(
f"(between/c {n} {m})", lambda i: is_real(i) and i <= m and i >= n, (1, 1)
Expand Down
12 changes: 8 additions & 4 deletions auto_editor/lib/data_structs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from collections.abc import Iterator
from fractions import Fraction
from io import StringIO
from typing import Any
Expand Down Expand Up @@ -105,11 +106,14 @@ def __init__(self, val: list):
def __len__(self) -> int:
return len(self.val)

def __getitem__(self, index: int) -> object:
return self.val[index]
def __getitem__(self, key: int | slice) -> Any:
if isinstance(key, slice):
return Quoted(self.val[key])

def __iter__(self) -> list:
return self.val
return self.val[key]

def __iter__(self) -> Iterator:
return self.val.__iter__()

def __contains__(self, item: object) -> bool:
return item in self.val
Expand Down
3 changes: 3 additions & 0 deletions resources/scripts/scope.pal
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@
))

(assert (= (apply add1 #(4)) 5))
(assert (= (apply add1 '(4)) 5))
(assert (= (apply sub1 #(4)) 3))
(assert (equal? (map add1 '(3 4 5)) '(4 5 6)))

(assert (equal? ('(3 4 5 6) 0 4 2) '(3 5)))

0 comments on commit ce43937

Please sign in to comment.