News for hackers. Stuff that matters.

jhylton

Re:Python's Preprocessor – Pydong on Friday August 23, 2024 @05:09PM (#41333123)
No worries. I was working at PythonLabs at the time, so I guess you could say that adding Easter eggs to Python was part of my day job.
Re:Python extensions should be lazy on Wednesday August 07, 2024 @07:01PM (#41186394)
You could create a custom C type that wrapped an arbitrary AST node and dynamically created values for attributes when you accessed them. The values would also be wrappers around the next AST node, and they could generate new AST nodes on writes. Python objects would be created on traversal, but each one would be smaller. It wouldn’t use Python lists to handle repeated fields It seems like a non-trivial implementation, but not fundamentally hard.

The analogy with numpy doesn’t seem quite right, as Raymond observes, because numpy depends on lots of builtin operations that operate on the underlying data representation. We don’t have any such code for the AST. You’ll still want to write Python code to traverse, inspect, and modify the AST.