3 ms·
As the sibling noted, Python has a built-in AST parser [1] which I believe (not 100% sure) is used in libraries like Numba to JIT Python functions [2]. But fun
by eslaught 4y ago
As the sibling noted, Python has a built-in AST parser [1] which I believe (not 100% sure) is used in libraries like Numba to JIT Python functions [2].
But fundamentally, the difference between built-in and provided as a library is not really as wide as it once was. Rust libraries use a third-party library for parsing code for procedural macros [3] which is pretty pervasive, and as I noted libclang for C++ is a thing (though definitely less common).
So at least in my mind, the key difference in Lisp (for languages today) is not so much having this be a capability at all, it's more having it be expressed in terms of data structures lightweight enough that regular Joe programmer can pick them up and use them with relative ease. (Whereas, using Python's AST module and figuring out how to do code generation is definitely more than the average programmer is going to figure out.)
Even the reader can be customized in some syntax-ful languages. Terra is not mainstream but it provides this [4]. There are probably others.
[1]: https://docs.python.org/3/library/ast.html https://docs.python.org/3/library/ast.html
[2]: https://numba.pydata.org/ https://numba.pydata.org/
[3]: https://crates.io/crates/syn https://crates.io/crates/syn
[4]: https://terralang.org/api.html#embedding-new-languages-inside-lua https://terralang.org/api.html#embedding-new-languages-insid...
- deterministic 4y agoQuite a few languages can do the same. Including Haskell, OCaml etc. https://wiki.haskell.org/A_practical_Template_Haskell_Tutorial https://wiki.haskell.org/A_practical_Template_Haskell_Tutori... https://ocaml.org/docs/metaprogramming https://ocaml.org/docs/metaprogramming