How to trace?

15 views
Skip to first unread message

Skip Montanaro

unread,
Aug 19, 2014, 4:07:34 PM8/19/14
to mac...@googlegroups.com
I downloaded and tried MacroPy today, with the thought that I would initially use it to trace execution of some code I was having trouble with. This is the first example shown on the PyPI page:

with trace:
    sum
([x + 5 for x in range(3)])


Not knowing any better, I tried this at the Python prompt:

import macropy.tracing
with trace:
 sum
([x + 5 for x in range(3)])

This, unfortunately fails:

Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
AttributeError: __exit__


Reading elsewhere later, I discovered that I was missing some other initialization, but I'm not entirely sure what that is. Assume I want to simply trace the body of a single function:

def f(a, b):
   
return a*5 + b / 7.0


If I don't want to disturb any other code, what do I need to do beyond this transformation?

def f(a, b):
   
from macropy.tracing import trace:
   
with trace:
       
return a*5 + b / 7.0


In fact, looking at the tracing examples in the doc: https://github.com/lihaoyi/macropy#tracing (fourth example, "Lastly, trace can be used as a block macro") it appears I've done what I'm supposed to do. But clearly that is not enough. Shouldn't there be a "hello world" example which is complete in its entirety on PyPI or as part of the documentation?

Thanks,

Skip

Haoyi Li

unread,
Aug 19, 2014, 4:38:39 PM8/19/14
to Skip Montanaro, mac...@googlegroups.com
MacroPy needs to be bootstrapped *before* you load any file that uses macros. There is a complete example here, kinda tricky but unavoidable given the restrictions of how macropy works (i.e. at runtime, no pre-processing). Go try it ^_^


--
You received this message because you are subscribed to the Google Groups "macropy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to macropy+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages