Closed mbrezu closed 11 years ago
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
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!
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
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!
Thanks for your suggestion; you are entirely right! I will find some time to shuffle it around.
Made the top "banner" example into an executable REPL session, and linked to the examples which also have nice-to-use REPL sessions
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
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.
I installed macropy from git (git clone, python setup.py install).
I go to a python shell and try the case classes example.
I'm probably missing something obvious :-)