Karsten Johansson on Nostr: Why doesn't #Python have #Lisp style macros? For example, here is something that ...
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!
Published at
2023-09-10 20:05:15Event JSON
{
"id": "cd1396dfa921011e75130b28ec855df944fa0b51b18a9397d2eea8f98bff4cd0",
"pubkey": "c11820d607ae2f62975c6c7e016f177c5c5c0a4bb2aa38a4798dcd142ef6d5af",
"created_at": 1694376315,
"kind": 1,
"tags": [
[
"t",
"python"
],
[
"t",
"lisp"
],
[
"proxy",
"https://infosec.exchange/users/ksaj/statuses/111042646220959450",
"activitypub"
]
],
"content": "Why doesn't #Python have #Lisp style macros?\n\nFor example, here is something that should be able to be used in code generation:\n\ns = \"This is a string that I want to turn into a list\"\nprint(s.split(' ', -1))\n\nIt'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.\n\nThere doesn't really seem to be anything stopping Python from being able to do this, except the lack of implementation.\n\nOr is it there, and I just don't know about it yet?\n\nMaybe a related question: Does Python have something like Lisp's (compile ....) because that would immediately call for Lisp style macros!",
"sig": "fb4fd014ac0d6157e0d011258a208212f57d0d55972285f107352b3123dc6da024fe9a1caafafb509657faa879fa289fc09fef19cc15ba3474fb29a284508411"
}