Better HN
topnewbestaskshowjobs
Log inSign up

jhylton

8 karma · joined Aug 7, 2024 (2y ago) · 2 submissions

Python, Google search, Shakespeare, etc.
Submissions

comment 2y ago · link · parent

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.

comment 2y ago · link · parent

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.