Global Feed Post Login
Replying to Avatar Karsten Johansson

Why doesn't #Python have #Lisp style macros?

For example, here is something that should be able to be used in code generation:

s = "This is a string that I want to turn into a list"

print(s.split(' ', -1))

It's a lame example, but it shows the point cleanly. With a Lisp style macro, I would be able to compile this as a list, instead of creating the lisp at runtime every time.

There doesn't really seem to be anything stopping Python from being able to do this, except the lack of implementation.

Or is it there, and I just don't know about it yet?

Maybe a related question: Does Python have something like Lisp's (compile ....) because that would immediately call for Lisp style macros!

Avatar
jaseg @ 39C3 (☎️ 57933) 2y ago

nostr:npub1cxnpl3gfu5h4h5yx5x0he5ulqkcgrdme3dsrqj0h92f7et7h64dsz490qc There was a project called macropy that did basically this by installing import hooks that could do arbitrary transformations both before and after AST parsing.

https://pypi.org/project/MacroPy/

Reply to this note

Please Login to reply.

Discussion

No replies yet.