merits of Lisp vs Python

André Thieme address.good.until.2006.dec.22 at justmail.de
Sun Dec 10 16:33:37 EST 2006


Steven D'Aprano schrieb:
> On Sun, 10 Dec 2006 01:53:50 +0100, André Thieme wrote:
> 
>> You could maybe give another example: how would one realize something
>> like (memoize function) in Python?
> 
> By spending thirty seconds googling:
> 
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325205
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498110
> 
> If your needs are very simple, something as simple as this will do it:
> 
> def memoize(func):
>     def f(arg, _cache={}):
>         if _cache.has_key(arg):
>             return _cache[arg]
>         t = func(arg)
>         _cache[arg] = t
>         return t
>     return f
> 

Yes, you are right, again this can be done with functional programming.
My examples also were not better than those of Kenny.
But anyway, in Lisp you can save some code. Not much in this situation.
Instead of   function = memoize(function)
one could just say: memoize(function).


>> Or (defmethod name :after ..)?
> 
> I don't even know what that means. Would you like to translate?

Also this won't be very hard to do in Python.
It just means: if you have a method with the name "name" and call it,
then this after-method will be called right after and do some side effect.

In Lisp it is built in. But with some effort it could be done in Python
too. The idea is, that small savings sum up, so macros do make sense.


André
-- 



More information about the Python-list mailing list