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!

Reply to this note

Please Login to reply.

Discussion

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/

Doesn't that kind of defeat the purpose of any interpreted language? For compiled languages I totally agree.