I have seen one answer of How does Lisp let you redefine the language itself? Stack Overflow question (answered by Noah Lavine):
Macros aren't quite a complete redefinition of the language, at least as far as I know (I'm actually a Schemer; I could be wrong), because there is a restriction. A macro can only take a single subtree of your code, and generate a single subtree to replace it. Therefore you can't write whole-program-transforming macros, as cool as that would be.
After reading this I am curious about whether there are "whole-program-transforming macros" in Lisp or Scheme (or some other language).
If not then why?
Update
One kind of use case e.g.
As in stumpwm code here are some functions all in different lisp source files uses a dynamic/global defvar variable *screen-list* that is defined in primitives.lisp , but used in screen.lisp, user.lisp, window.lisp. (Here each files have functions, class, vars related to one aspect or object)
Now I wanted to define these functions under the closure where *screen-list* variable available by let form, it should not be dynamic/global variable, But without moving these all functions into one place (because I do not want these functions to lose place from their related file) So that this variable will be accessible to only these functions.
Above e.g. equally apply to label and flet, so that it will further possible that we could make it like that only required variable, function will be available, to those who require it.
Note one way might be implement and use some macro defun_with_context for defun where first argument is context where let, flet variables definend. But apart from it could it be achieved by reader-macro as Vatine and Gareth Rees answered.
You quoted Noah Lavine as saying:
A macro can only take a single subtree of your code, and generate a single subtree to replace it
This is the case for ordinary macros, but reader macros get access to the input stream and can do whatever they like with it.
See the Hyperspec section 2.2 and the set-macro-character
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With