Skip to content

Instantly share code, notes, and snippets.

@yorickvP
Last active March 9, 2023 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorickvP/08afdaae98cad3516a9629e7e8df343d to your computer and use it in GitHub Desktop.
Save yorickvP/08afdaae98cad3516a9629e7e8df343d to your computer and use it in GitHub Desktop.
DeepEvaluated = int | float | str | "String" | None | dict[string, "Evaluated"] | list["Evaluated"] | Function
Evaluated = int | float | "String" | None | dict[string, "Value"] | list["Value"] | "Function"
T = TypeVar('T', bound=Evaluated)
class Value:
def __init__(self, x: Value | Evaluated | DeepEvaluated):
"""
Make a new Value from python
"""
...
def force(typeCheck=Evaluated: Literal[T]) -> T:
"""
Force this value into the specified type (default Evaluated).
Throws TypeError if this is impossible.
"""
...
def forceDeep(self) -> DeepEvaluated:
...
def __call__(self, *arg, **kwarg) -> Value:
return self.force(Function)(*arg, **kwarg)
def __int__(self) -> int:
return self.force(int)
def __str__(self) -> str:
return str(self.force(str))
def __float__(self) -> float:
return self.force(float)
def __len__(self) -> int:
return len(self.force(dict[string, Value] | list[Value]))
def __getitem__(self, i: int) -> Value:
return self.force(list[Value])[i]
def __getitem__(self, i: string) -> Value:
return self.force(dict[string, Value])[i]
def is_evaluated(self) -> bool:
...
class Function(Value):
def __call__(self, arg: Value | Evaluated | DeepEvaluated) -> Value:
pass
class String(Value):
def __str__(self) -> str:
...
@property
def context(self) -> List[str]:
...
def evalString(x: string) -> Value:
...
# TODO:
# - attribute positions
# - distinction between primops and functions
# - paths vs strings vs contextful strings
# - external types
# - lambdas from python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment