Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed pattern.py on PyPy

  • Loading branch information...
commit ddbfadc34cb0ebc46649a769c8c93b2075718f70 1 parent cdbb413
@lihaoyi authored
View
113 macropy/demo.py
@@ -1,113 +0,0 @@
-
-from sqlalchemy import *
-from macropy.macros2.linq import macros, sql, query, generate_schema
-
-engine = create_engine("sqlite://")
-for line in open("macros2/linq_test_dataset.sql").read().split(";"):
- engine.execute(line.strip())
-
-db = generate_schema(engine)
-
-query_string = sql%((x.name, x.area) for x in db.bbc if x.area > 10000000)
-print type(query_string)
-print query_string
-
-"""
-Demos
-=====
-
-tracing
--------
-from macropy.macros2.tracing import macros
-from macropy.macros2.t racing import *
-with trace:
- x = (1 + 2)
- y = x * x + 7
-
-
-quicklambda
--------
-from macropy.macros.quicklambda import macros, f
-
-print map(f%_[0], ['omg', 'wtf', 'bbq'])
-print reduce(f%(_ + _), [1, 2, 3])
-
-
-adts
--------
-from macropy.macros.adt import macros
-from macropy.macros.adt import *
-
-@case
-class Point(x, y): pass
-
-p = Point(1, 2)
-
-print str(p)
-print p.x
-print p.y
-print Point(1, 2) == Point(1, 2)
-
-
-pattern matching
-----------------
-
-
-LINQ
-----
-from sqlalchemy import *
-from macropy.macros2.linq import macros, sql, generate_schema
-
-engine = create_engine("sqlite://")
-for line in open("macros2/linq_test_dataset.sql").read().split(";"):
- engine.execute(line.strip())
-
-db = generate_schema(engine)
-
-results = engine.execute(
- sql%((x.name, x.area) for x in db.bbc if x.area > 10000000)
-).fetchall()
-
-results = engine.execute(
- sql%(
- x.name for x in db.bbc
- if x.gdp / x.population > (
- y.gdp / y.population for y in db.bbc
- if y.name == 'United Kingdom'
- )
- if (x.region == 'Europe')
- )
-).fetchall()
-
-for line in results: print line
-
-
-
-
-from macropy.macros.adt import macros
-from macropy.macros.adt import *
-from macropy.macros.pattern import macros
-from macropy.macros.pattern import *
-
-
-@case
-class Add(left, right):
- pass
-
-@case
-class Mul(left, right):
- pass
-
-@case
-class Num(x):
- pass
-
-def compute(expr):
- with switch(expr):
- if Num(n):
- return n
- elif Add(x, y):
- return compute(x) + compute(y)
- elif Mul(x, y):
- return compute(x) * compute(y)
-"""
View
3  macropy/macros/pattern.py
@@ -176,7 +176,7 @@ def default_unapply(self, matchee, kw_keys):
kw_dict = {}
arg_spec = inspect.getargspec(self.clazz.__init__)
for arg in arg_spec.args:
- if arg is not 'self':
+ if arg != 'self':
pos_values.append(getattr(matchee, arg, None))
# if arg_spec.varargs:
# pos_values.extend(getattr(matchee, varargs, []))
@@ -196,7 +196,6 @@ def match(self, matchee):
else:
pos_vals, kw_dict = self.default_unapply(matchee,
self.kwMatchers.keys())
-
for (matcher, sub_matchee) in zip(self.positionalMatchers,
pos_vals):
updates.extend(matcher.match(sub_matchee))
View
2  macropy/rundemo.py
@@ -1,2 +0,0 @@
-import macropy.core.macros
-import demo
View
5 setup.py
@@ -61,9 +61,8 @@ class Point(x, y): pass
from distutils.core import setup
setup(name='MacroPy',
- version='0.1.1',
- description='Macros for Python: Quasiquotes, Case Classes, LINQ and more!'
- 'and good intentions',
+ version='0.1.2',
+ description='Macros for Python: Quasiquotes, Case Classes, LINQ and more!',
long_description=__doc__,
license='BSD',
author='Li Haoyi',
Please sign in to comment.
Something went wrong with that request. Please try again.