Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch etuple #21

Merged
merged 2 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions etuples/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from collections.abc import Generator, Sequence
from typing import Callable

from multipledispatch import dispatch

etuple_repr = reprlib.Repr()
etuple_repr.maxstring = 100
etuple_repr.maxother = 100
Expand Down Expand Up @@ -337,6 +339,7 @@ def __hash__(self):
return hash(self._tuple)


@dispatch([object])
def etuple(*args, **kwargs):
"""Create an ExpressionTuple from the argument list.

Expand Down
8 changes: 7 additions & 1 deletion etuples/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def apply_ExpressionTuple(rator, rands):
operator, arguments, term = rator, rands, apply


@dispatch(object)
def etuplize_fn(op):
return etuple


@dispatch(object)
def etuplize(
x,
Expand Down Expand Up @@ -140,6 +145,7 @@ def etuplize_step(
return_bad_args=return_bad_args,
convert_ConsPairs=convert_ConsPairs,
):

if isinstance(x, ExpressionTuple):
yield x
return
Expand Down Expand Up @@ -182,6 +188,6 @@ def etuplize_step(
)
et_args.append(e)

yield etuple(et_op, *et_args, evaled_obj=x)
yield etuplize_fn(op)(et_op, *et_args, evaled_obj=x)

return trampoline_eval(etuplize_step(x))