etuples
etuples is a Python library that provides S-expression emulation using tuple-like objects. It allows for the creation of functional expression trees that can be explicitly evaluated. The library is currently at version 0.3.10 and has an active development status with several releases in the past year.
Warnings
- gotcha Do not confuse `etuple` objects with Python's built-in `tuple` type. `etuple` instances are specifically designed for S-expression emulation, representing an operation and its arguments as an unevaluated expression, rather than a simple immutable sequence.
- gotcha Failing to explicitly evaluate an `etuple` object will result in operating on the `ExpressionTuple` object itself, not its computed value. This is a common mistake when users expect immediate computation akin to function calls.
- gotcha As `etuples` is in its 0.x version series, minor version increments (e.g., 0.3.x to 0.4.x) might introduce breaking API changes. Developers should review the changelog carefully when upgrading to a new minor version.
Install
-
pip install etuples
Imports
- etuple
from etuples import etuple
- etuplize
from etuples import etuplize
- ExpressionTuple
from etuples.core import ExpressionTuple
Quickstart
from operator import add
from etuples import etuple, etuplize
# Create an expression tuple
et = etuple(add, 1, 2)
print(f"Expression: {et}")
# Evaluate the expression
result = et.eval()
print(f"Result of evaluation: {result}")
# etuplize can convert callables into etuples
def my_func(a, b):
return a * b
et_func = etuplize(my_func)
et_expression = et_func(3, 4)
print(f"Et_expression: {et_expression}")
print(f"Result of et_expression: {et_expression.eval()}")