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

NameError: name 'case' is not defined #30

Closed
mbrezu opened this issue May 17, 2013 · 8 comments
Closed

NameError: name 'case' is not defined #30

mbrezu opened this issue May 17, 2013 · 8 comments

Comments

@mbrezu
Copy link

mbrezu commented May 17, 2013

I installed macropy from git (git clone, python setup.py install).

I go to a python shell and try the case classes example.

Python 2.7.4 (default, Apr 19 2013, 18:32:33) 
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from macropy.macros.adt import macros, case
0=[]=====> MacroPy Enabled <=====[]=0
>>> @case
... class Point(x, y): pass
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'case' is not defined

I'm probably missing something obvious :-)

@jnhnum1
Copy link
Collaborator

jnhnum1 commented May 17, 2013

Because MacroPy modifies the import process, you need to import macropy.core.macros (as in the REPL example in the readme) before you import specific macros.

so

>>> import macropy.core.macros
0=[]=====> MacroPy Enabled <=====[]=0
>>> from macropy.macros.adt import macros, case
>>> @case
... class Point(x, y): pass
>>>

should work fine

@jnhnum1 jnhnum1 closed this as completed May 17, 2013
@mbrezu
Copy link
Author

mbrezu commented May 17, 2013

Thanks!

Maybe adding that extra line to the examples would be useful. Or add a 'getting started' section, which includes all the necessary lines, so people who only want to spend 10 minutes trying out macropy (like me) only have to copy-paste a few lines and be instantly convinced to spend more time.

Macropy looks like a great library, keep up the good work!

@lihaoyi
Copy link
Owner

lihaoyi commented May 17, 2013

It's already in the Rough Overview and Detailed Guide for the non-REPL macros; maybe I should add a reminder for those using the REPL

@mbrezu
Copy link
Author

mbrezu commented May 17, 2013

A suggestion: people in a hurry scan for 'Getting Started', 'Quick start' and similar keywords. Starting the documentation with a small, documented REPL session showing case classes (and maybe a bit of pattern matching) should help. Or at least provide a link to such a document at the start of the README.

Also, the 'Rough overview' starts by showing how to define macros. IMHO it's better to start with a few examples of using existing macros. Some people (e.g. me) will start by using the existing macros and later (if ever) be interested in defining their own.

Thanks!

@lihaoyi
Copy link
Owner

lihaoyi commented May 17, 2013

Thanks for your suggestion; you are entirely right! I will find some time to shuffle it around.

@lihaoyi
Copy link
Owner

lihaoyi commented May 17, 2013

Made the top "banner" example into an executable REPL session, and linked to the examples which also have nice-to-use REPL sessions

@AndreaCrotti
Copy link

Hi everyone,
I am playing around with Macropy and I have the same issue described here earlier, I copied and pasted the example (adding the import you mentioned) and it still fails with python 2.7.8

import macropy.core.macros
from macropy.case_classes import macros, case

@case
class Point(x, y):
    pass

p = Point(1, 2)

print str(p) # Point(1, 2)
print p.x    # 1
print p.y    # 2
print Point(1, 2) == Point(1, 2) # True
x, y = p
print x, y   # (1, 2)

Any idea about what the problem might be?

It seems like the macropy is never enabled because I also don't see that message..
thanks

@pigmej
Copy link

pigmej commented Sep 3, 2014

It's not that you need import, you need to import the file with macros, not the macropy itself

So if the file a.py contains macros, then you need to create b.py and import a. that's all.

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

5 participants