3 ms·
I see the docs mention that these only work when importing modules. The dev version of IPython lets you transform the AST of code that is typed in the REPL. I
by jasongrout 13y ago
I see the docs mention that these only work when importing modules. The dev version of IPython lets you transform the AST of code that is typed in the REPL. It would be really cool to see an IPython AST transformer based on this. Here is an example from the test files in IPython: https://github.com/ipython/ipython/blob/master/IPython/core/tests/test_interactiveshell.py#L451 https://github.com/ipython/ipython/blob/master/IPython/core/...
- lihaoyi 13y agoYep, there's an issue for that! https://github.com/lihaoyi/macropy/issues/14 https://github.com/lihaoyi/macropy/issues/14 I've also gotten a basic implementation working in the CPython REPL, which requires you to run a function `macro_repl()` before you can use them. A Macro powered REPL would be super cool!
- lihaoyi 13y agoMacroPy now works with the CPython REPL: PS C:\Dropbox\Workspace\6.945\Project> python Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import macropy.core.macros 0=[]=====> MacroPy Enabled <=====[]=0 >>> from macropy.macros2.tracing import macros, trace >>> trace%[x*2 for x in range(3)] range(3) -> [0, 1, 2] (x * 2) -> 0 (x * 2) -> 2 (x * 2) -> 4 [(x * 2) for x in range(3)] -> [0, 2, 4] [0, 2, 4] It's somewhat hacky, but it seems to work pretty well. I went through the examples and most of them work perfectly in the REPL, except for those whose have blank-lines-in-class-def confuse it