[pypy-svn] r38169 - pypy/dist/pypy/doc

arigo at codespeak.net arigo at codespeak.net
Thu Feb 8 16:45:28 CET 2007


Author: arigo
Date: Thu Feb  8 16:45:26 2007
New Revision: 38169

Modified:
   pypy/dist/pypy/doc/objspace.txt
Log:
Thunk space: document pypymagic.lazy.


Modified: pypy/dist/pypy/doc/objspace.txt
==============================================================================
--- pypy/dist/pypy/doc/objspace.txt	(original)
+++ pypy/dist/pypy/doc/objspace.txt	Thu Feb  8 16:45:26 2007
@@ -325,9 +325,9 @@
     $ py.py -o thunk
     >>>> from pypymagic import thunk
     >>>> def f():
-    ...     print 'computing...'
-    ...     return 6*7
-    ...
+    ....    print 'computing...'
+    ....    return 6*7
+    ....
     >>>> x = thunk(f)
     >>>> x
     computing...
@@ -339,6 +339,24 @@
     computing...
     <pypy type 'int'>
 
+There is also a decorator for functions whose result can be computed
+lazily (the function appears to return a result, but it is not really
+invoked before the result is used, if at all):
+
+    $ py.py -o thunk
+    >>>> from pypymagic import lazy
+    >>>> @lazy
+    .... def f(x):
+    ....    print 'computing...'
+    ....    return x * 100
+    ....
+    >>>> lst = [f(i) for i in range(10)]
+    >>>> del lst[1:9]
+    >>>> lst
+    computing...
+    computing...
+    [0, 900]
+
 
 .. _`flow object space`:
 



More information about the Pypy-commit mailing list