[pypy-svn] r29573 - pypy/extradoc/talk/ep2006

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Jul 1 23:09:32 CEST 2006


Author: cfbolz
Date: Sat Jul  1 23:09:31 2006
New Revision: 29573

Added:
   pypy/extradoc/talk/ep2006/fibonacci.py
   pypy/extradoc/talk/ep2006/fibonacci2.py
   pypy/extradoc/talk/ep2006/fibonacci3.py
   pypy/extradoc/talk/ep2006/fibonacci4.py
   pypy/extradoc/talk/ep2006/fork_demo.py
   pypy/extradoc/talk/ep2006/usecases-planning.txt
Log:
(arigo, cfbolz): plans for the ep talk. seems way to much material for half an
hour :-(


Added: pypy/extradoc/talk/ep2006/fibonacci.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ep2006/fibonacci.py	Sat Jul  1 23:09:31 2006
@@ -0,0 +1,32 @@
+"""
+This is a typical Functional Programming Languages demo, computing the
+Fibonacci sequence by using an infinite lazy linked list.
+"""
+
+try:
+    newvar    # only available in 'py.py -o logic'
+except NameError:
+    print __doc__
+    raise SystemExit(2)
+
+# ____________________________________________________________
+
+Fibonacci = (1, (1, newvar()))
+
+def generate():
+    lst = Fibonacci
+    while 1:
+        (a, (b, tail)) = lst
+        wait_needed(tail)
+        newtail = newvar()
+        unify(tail, (a+b, newtail))
+        lst = lst[1]
+
+def display(limit):
+    cur = Fibonacci
+    for i in range(limit):
+        print cur[0]
+        cur = cur[1]
+
+uthread(generate)
+uthread(display, 15)

Added: pypy/extradoc/talk/ep2006/fibonacci2.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ep2006/fibonacci2.py	Sat Jul  1 23:09:31 2006
@@ -0,0 +1,40 @@
+"""
+This is a typical Functional Programming Languages demo, computing the
+Fibonacci sequence by using an infinite lazy linked list.
+"""
+
+try:
+    newvar    # only available in 'py.py -o logic'
+except NameError:
+    print __doc__
+    raise SystemExit(2)
+
+# ____________________________________________________________
+
+class Node:
+    def __init__(self, head, tail):
+        self.head = head
+        self.tail = tail
+
+Fibonacci = Node(1, Node(1, newvar()))
+
+def generate():
+    lst = Fibonacci
+    while 1:
+        a = newvar()
+        b = newvar()
+        tail = newvar()
+        unify(lst, Node(a, Node(b, tail)))
+        wait_needed(tail)
+        newtail = newvar()
+        bind(tail, Node(a+b, newtail))
+        lst = lst.tail
+
+def display(limit):
+    cur = Fibonacci
+    for i in range(limit):
+        print cur.head
+        cur = cur.tail
+
+uthread(generate)
+uthread(display, 15)

Added: pypy/extradoc/talk/ep2006/fibonacci3.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ep2006/fibonacci3.py	Sat Jul  1 23:09:31 2006
@@ -0,0 +1,39 @@
+"""
+This is a typical Functional Programming Languages demo, computing the
+Fibonacci sequence by using an infinite lazy linked list.
+"""
+
+try:
+    newvar    # only available in 'py.py -o logic'
+except NameError:
+    print __doc__
+    raise SystemExit(2)
+
+# ____________________________________________________________
+
+class Node:
+    def __init__(self, head, tail):
+        self.head = head
+        self.tail = tail
+
+Fibonacci = Node(1, Node(1, newvar()))
+
+def generate():
+    lst = Fibonacci
+    while 1:
+        a = newvar()
+        b = newvar()
+        tail = newvar()
+        unify(lst, Node(a, Node(b, tail)))
+        wait_needed(tail)
+        unify(lst, Node(a, Node(b, Node(a+b, newvar()))))
+        lst = lst.tail
+
+def display(limit):
+    cur = Fibonacci
+    for i in range(limit):
+        print cur.head
+        cur = cur.tail
+
+uthread(generate)
+uthread(display, 15)

Added: pypy/extradoc/talk/ep2006/fibonacci4.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ep2006/fibonacci4.py	Sat Jul  1 23:09:31 2006
@@ -0,0 +1,37 @@
+"""
+This is a typical Functional Programming Languages demo, computing the
+Fibonacci sequence by using an infinite lazy linked list.
+"""
+
+try:
+    newvar    # only available in 'py.py -o logic'
+except NameError:
+    print __doc__
+    raise SystemExit(2)
+
+# ____________________________________________________________
+
+class Node:
+    def __init__(self, head, tail):
+        self.head = head
+        self.tail = tail
+
+Fibonacci = Node(1, Node(1, newvar()))
+
+def generate():
+    lst = Fibonacci
+    while 1:
+        a = lst.head
+        b = lst.tail.head
+        wait_needed(lst.tail.tail)
+        unify(lst, Node(a, Node(b, Node(a+b, newvar()))))
+        lst = lst.tail
+
+def display(limit):
+    cur = Fibonacci
+    for i in range(limit):
+        print cur.head
+        cur = cur.tail
+
+uthread(generate)
+uthread(display, 15)

Added: pypy/extradoc/talk/ep2006/fork_demo.py
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ep2006/fork_demo.py	Sat Jul  1 23:09:31 2006
@@ -0,0 +1,70 @@
+choicepoints = []
+
+def choice():
+    child = fork()
+    if child is not None:
+        choicepoints.append(child)
+        return 0
+    else:
+        return 1
+
+class Fail(Exception):
+    pass
+
+
+
+invalid_branches = dict.fromkeys([
+    (0, 0, 0),
+    (0, 0, 1),
+    (0, 1),
+    (1, 0, 0, 0),
+    (1, 0, 0, 0, 0),
+    (1, 0, 0, 0, 1),
+    (1, 0, 1),
+    (1, 1, 0, 0),
+    ])
+
+def search():
+    path = []
+    for i in range(10):
+        path.append(choice())
+        if tuple(path) in invalid_branches:
+            raise Fail
+    return path
+
+# ^ ^ ^ that's quite cool code I think :-)
+# yes, I agree :-)
+# much easier than doing it by hand
+
+
+
+# hum, not really RPython, the dict with var-sized tuples
+# hum
+# we could use lists
+# and use a list of lists insteaed of a dict
+# good enough
+# I can prepare that
+# ok, great
+# note that fork is a class method or something
+# ah, I see
+# will just try
+# also, I was about to write something like:
+
+search_coro = ...
+choicepoints.append(search_coro)
+
+while choicepoints:
+    try:
+        res = choicepoints.pop().switch()
+    except Fail:
+        pass
+    else:
+        print "found it!", res
+
+# is this searching for only one? then we will get (0, )
+# no, answers must be 10 numbers long
+# ah, I see
+# also if we don't add a break after the print, it will
+# find all solutions
+# oh, right
+

Added: pypy/extradoc/talk/ep2006/usecases-planning.txt
==============================================================================
--- (empty file)
+++ pypy/extradoc/talk/ep2006/usecases-planning.txt	Sat Jul  1 23:09:31 2006
@@ -0,0 +1,39 @@
+What can PyPy do for you?
+=========================
+
+Peek under the hood
+-------------------
+
+ - sys.pypy_repr() with small ints
+
+Stackless stuff
+---------------
+
+ - lightweight threadlets similar to what stackless python provides
+
+ - tasklet cloning
+
+ - gc: performance/memory/feature tradeoffs: e.g. (check if and) show an
+   example where a refcounting pypy uses less Unix process memory than a Boehm
+   one (but of course the latter is faster).  Mention that tasklet cloning
+   requires a gc which is (ATM) a bit slower.
+ 
+Lazy stuff
+----------
+ 
+ - lazy evaluation with the thunk object space
+   try running demo/sharedref on pypy-c-thunk.
+ 
+ - Oz-like dataflow variables with the logic object space
+   py.py -o logic --usemodules=_stackless fibonacci{,2,3,4}.py
+
+Compiling
+---------
+
+ - algo example, e.g. sieve of eratosthenes
+ - ctypes example
+ - Writing compatible extension modules for PyPy and CPython with the PyPy
+   extension compiler
+
+ - The Javascript backend and its uses
+



More information about the Pypy-commit mailing list