On Fri, Dec 25, 2020 at 7:58 PM Pete Dietl <petedi...@gmail.com> wrote: > Now for Make, there are no semantics for telling whether or not it is > lexically or dynamically scoped. This is because previously the only local > variables were the function arguments. Since these arguments are always named > the same thing, even if the language were dynamically scoped, successive > function calls would create new function argument variables which shadow the > previous ones. If you try to use eval to create functions or variables on the > fly, it works but both are added to the global scope.
There is an easy demonstration (adapted from https://en.wikipedia.org/wiki/Scope_(computer_science) ): ---- x=1 g=$(info $x) f=$(foreach x,3,$g) $f $(info $x) ---- Here, `foreach` can be replaced by `let`. The first output is "3", demonstrating dynamic scoping. Behavior aside, the source code of GNU make is structured so that make has dynamic scoping. Apart from these remarks, I agree with your analysis and have also observed that assignments in $(eval) will assign at the global scope (and not the scope at the top of the stack). I am not sure whether that is a feature or a bug. Regards, - Jouke > > On Fri, Dec 25, 2020 at 10:00 AM Jouke Witteveen <j.wittev...@gmail.com> > wrote: >> >> * NEWS: Use "local" instead of the incorrect "lexically-scoped". >> * doc/make.texi: Refer to let/foreach variables as local variables. >> --- >> This is an erratum on the addition of $(let ...). During an early review >> of $(let ...), thutt cautioned that it did not implement "full semantic >> scoping" [sic]. While I did not understand fully what they meant by >> that, I countered that it was not intended to determine a scope based on >> for example which file a definition of a rule occurred in, but simply by >> the parentheses delimiting the let expression. Only in that sense was it >> lexical scoping. Technically, make variables are dynamically scoped. >> >> This patch replaces "lexically scoped" not by "dynamically scoped", but >> by "local", since that is the whole point after all. It also includes >> variables with local scope (from let and foreach) in several other >> places where variables are discussed, and makes explicit that variables >> in make are dynamically scoped. >> >> NEWS | 4 ++-- >> doc/make.texi | 21 +++++++++++++++------ >> 2 files changed, 17 insertions(+), 8 deletions(-) >>