An expression binding
A reader who will never be satisfied with a partial solution-Richard Davies-raises the question of whether we can always move the binding to a separate expression. Let's take a quick look at why we want to do this and show a great way for Comp.lang.python contributors.
Let's first review the bindings class in the functional module. By using the properties of that class, we can ensure that a special name has only one meaning within the given block's scope:
Listing 1: The Python FP section with protected rebind
>>>
from
functional
import
*
>>> let = Bindings()
>>> let.car =
lambda
lst: lst[0]
>>> let.car =
lambda
lst: lst[2]
Traceback (innermost last):
File "<stdin>", line 1,
in
?
File "d:\tools\functional.py", line 976,
in
__setattr__
raise
BindingError, "Binding '%s' cannot be modified." % name
functional.BindingError: Binding 'car' cannot be modified.
>>> let.car(range(10))
0