conditional computation

Gabriel Genellina gagsl-py at
Thu Oct 26 22:01:52 CEST 2006

At Thursday 26/10/2006 16:30, robert wrote:

>I want to use a computation cache scheme like
>         o = CACHECOMPUTE  complex-key-expr  expensive-calc-expr
>frequently and elegantly without writing complex-key-expr or 
>expensive-calc-expr twice.
>So its ugly:
>         _=complex-key-expr; o=cache.get(_) or 
> cache.setdefault(_,expensive-calc-expr)
>Any ideas?

The memoize pattern can help; in you can see an 
implementation using decorators.

Gabriel Genellina
Softlab SRL 

Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! -

More information about the Python-list mailing list