|
|
|
|
|
by srcreigh
1608 days ago
|
|
Some macro systems can create variables in a loop for you. You could make this macro, (define-all i 5 0)
;; creates i1 i2 i3 i4 i5 initialized to 0
That's somewhat impossible with functions. The closest you get is either an array/dict with only runtime error checking, or an external codegen program.I wrote a post [0] about how to do this in Racket. The macro generates ORM code based given a SQLite DB. Aka the compiler queries SQLite and generates table-column functions automatically. More potential benefits are: Better static error messages (can implement a type system using macros, example here[1]), and controlling execution order (can add lazy computation semantics). [0]: http://tech.perpetua.io/2022/01/generating-sqlite-bindings-w... [1]: https://gist.github.com/srcreigh/f341b2adaa0fe37c241fdf15f37... |
|