[Python-Dev] ANN: Pyrex - a language for writing Python extension modules

Greg Ewing greg@cosc.canterbury.ac.nz
Thu, 04 Apr 2002 18:52:10 +1200 (NZST)


Folks here may be interested in my latest
project: A new language specially designed for
writing Python extension modules.

Pyrex is more or less Python with C data types
added. You can write functions which freely
intermix operations on Python and C data, with
all Python reference counting and error checking
completely automated.

An example Pyrex module is shown below. For more
information, see:

http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/

where you can also download version 0.1 and try it
out. I'm very keen to get feedback on this, both to
find out whether people think it's useful, and to
help me debug it!

Oh, yeah, here's the example. It finds prime
numbers at C speed.

def primes(int kmax):
  cdef int n, k, i
  cdef int p[1000]
  result = []
  if kmax > 1000:
    kmax = 1000
  k = 0
  n = 2
  while k < kmax:
    i = 0
    while i < k and n % p[i] <> 0:
      i = i + 1
    if i == k:
      p[k] = n
      k = k + 1
      result.append(n)
    n = n + 1
  return result

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+