a=[ lambda t: t**n for n in range(4) ]

El Pitonero pitonero at gmail.com
Fri Apr 22 23:45:55 EDT 2005


Bengt Richter wrote:
> I still don't know what you are asking for, but here is a toy,
> ...
> But why not spend some time with the tutorials, so have a few more
cards in your deck
> before you try to play for real? ;-)

Communication problem.

All he wanted is automatic evaluation a la spreadsheet application.
Just like in Microsoft Excel. That's all.

There are many ways for implementing the requested feature. Here are
two:

(1) Push model: use event listeners. Register dependent quantities as
event listeners of independent quantities. When an independent quantity
is modified, fire off the event and update the dependent quantities.
Excel uses the push model.

(2) Pull model: lazy evaluation. Have some flag on whether an
independent quantity has been changed. When evaluating a dependent
quantity, survey its independent quantities recursively, and update the
cached copies whereever necessary.

Of course, combination of the two approaches is possible.

For Python, metaclasses and/or decorators and/or properties may help.

But functional languages are a more natural territory.




More information about the Python-list mailing list