Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern matching #40

Closed
macobo opened this issue May 29, 2013 · 10 comments
Closed

Pattern matching #40

macobo opened this issue May 29, 2013 · 10 comments

Comments

@macobo
Copy link
Contributor

macobo commented May 29, 2013

Pattern matching seems to be broken since 774461c, where also most of the tests got removed.

For example, the following code prints None on current revision (from readme):

from macropy.macros.pattern import macros, patterns
from macropy.macros.adt import macros, case

@case
class Rect(p1, p2): pass

@case
class Line(p1, p2): pass

@case
class Point(x, y): pass

def area(rect):
    with patterns:
        Rect(Point(x1, y1), Point(x2, y2)) << rect
        return (x2 - x1) * (y2 - y1)

print area(Rect(Point(1, 1), Point(3, 3))) # 4

The python code created (by unparse_ast) is following. Note the area function.

import inspect
from ast import *
from macropy.core import util
from macropy.core.macros import *
from macropy.core.lift import *
from macropy.core.lift import *
macros = Macros()

class PatternMatchException(Exception):
    '\n    Thrown when a nonrefutable pattern match fails\n    '
    pass

# snip, edited for brevity

@link_children
class Point(CaseClass):

    def __init__(self, *args, **kwargs):
        CaseClass.__init__(self, *args, **kwargs)
        pass
    _children = []
    _fields = ['x', 'y']

def area(rect):
    None
print area(Rect(Point(1, 1), Point(3, 3)))
@lihaoyi
Copy link
Owner

lihaoyi commented May 29, 2013

Ack, it looks like I screwed up a merge somewhere. Give me some time and I'll try to dig up the working version from the git history.

@lihaoyi
Copy link
Owner

lihaoyi commented May 29, 2013

Fixed it, I think 316b4ac

@lihaoyi lihaoyi closed this as completed May 29, 2013
@macobo
Copy link
Contributor Author

macobo commented May 29, 2013

Nope, sorry, this still doesn't work. Two new testcases for pattern_test.py that fail:

    def test_block_entered(self):
        " See https://github.com/lihaoyi/macropy/issues/40 "
        with patterns:
            return
        raise Exception("with block not entered")

    def test_pattern_function(self):
        def sum(foo):
            with patterns:
                Foo(x, y) << foo
                return x + y
        self.assertEquals(sum(Foo(1, 2)), 3)

@lihaoyi
Copy link
Owner

lihaoyi commented May 29, 2013

Hmmm lemme take another look

@lihaoyi lihaoyi reopened this May 29, 2013
@macobo
Copy link
Contributor Author

macobo commented May 29, 2013

No hurry, I'll be busy with other things for a few days.

@lihaoyi
Copy link
Owner

lihaoyi commented May 29, 2013

@jnhnum1 could you take a look at this?

@jnhnum1
Copy link
Collaborator

jnhnum1 commented May 29, 2013

yeah, I'm at work now but I'll take a look at it later tonight.

@lihaoyi
Copy link
Owner

lihaoyi commented May 31, 2013

I'm guessing we'll need to do this (#15) before we can be really confident of pattern matching working in the general case.

@lihaoyi
Copy link
Owner

lihaoyi commented Jun 1, 2013

I moved pattern matching (together with TCO) into /macropy/experimental/ in the last reshuffling, since it doesn't seem very stable or reliable at this point. We'll put it back into /macropy/ after we close this and #15.

@jnhnum1 jnhnum1 closed this as completed in 215f7bc Jun 1, 2013
@lihaoyi
Copy link
Owner

lihaoyi commented Jun 1, 2013

Sorry, I probably screwed up more than one thing while doing the big refactorings (e.g. converting how block macros work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants