[Python-3000] AST access (WAS: Adaptation vs. Generic Functions)

Robert Brewer fumanchu at amor.org
Sat Apr 15 02:43:42 CEST 2006


Talin wrote:
> What remains is a consise way to specify bound vs.
> unbound variables I would prefer not to have to
> restrict people to using a limited set of pre-declared
> undefined variables, i.e. X, Y, Z, etc.; plus I
> would want to be able to associate additional
> constraints with those unbound variables.

In Dejavu I did that with a separate "kwargs" attribute on the Expression object. You can set the kwargs attribute and it will be used when the Expression is evaluated:

>>> e = logic.Expression(lambda a, b, **kw: a + b + kw['c'])
>>> e.kwargs.update({'c': 16})
>>> e.evaluate(1, 8)
25

The "evaluate" method is a synonym for __call__ as well, and you can override previously-bound kwargs during evaluation:

>>> e(1, 8, c=256)
265


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20060414/e0a32dbf/attachment.html 


More information about the Python-3000 mailing list