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

Etuplize Python lists using cons #22

Open
rlouf opened this issue Oct 6, 2022 · 1 comment
Open

Etuplize Python lists using cons #22

rlouf opened this issue Oct 6, 2022 · 1 comment
Labels
question Further information is requested

Comments

@rlouf
Copy link
Contributor

rlouf commented Oct 6, 2022

etuplize currently transforms a Python list to an expression tuple that contains the elements of the list:

from etuples import etuplize
from etuples.core import InvalidExpression

et = etuplize([1, 2])
print(et)
# e(1, 2)

This expression tuple is invalid and cannot be evaluated:

try:
    et.evaled_obj
except InvalidExpression as e:
    print(e)
# ExpressionTuple does not have a callable operator.

I thus suggest that etuplize returns the following expression that uses cons, which can be emulated by registering _car and _cdr from cons.core for lists:

from cons.core import _car, _cdr, cons
from etuples import etuple

@_car.register(list)
def car_list(x):
    return cons

@_cdr.register(list)
def cdr_list(x):
    return etuple(*x, [])

et = etuplize([1, 2])
print(et)
# e(<class 'cons.core.ConsPair'>, 1, 2, [])
@brandonwillard brandonwillard added the question Further information is requested label Oct 10, 2022
@brandonwillard
Copy link
Member

The question is whether or not etuplize(x).evaled_obj == x should always hold, and I want to say "yes", but I'm not entirely sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants