Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: All the way up or current scope



On Sat, May 10, 2025 at 12:41 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> What version of ksh are you referring to?

I'm actually not certain.  Over the course of developing the zsh
implementation, I installed several versions of ksh, was told that at
least one of them was buggy and I should be installing something else
so switched to a different one, etc., and now the machine where I was
doing all the comparisons has been powered down for almost 8 months.

However ...

> To my great surprise, with dynamic scoping all functions apparently share the same set of variables.  In Zsh, when a nested function defines a local variable already defined in an enclosing function it gets its own variable that hides the existing one.

I think this explains why "all the way to the top" would appear to
disagree with ksh in testing.  If zsh scope didn't move to the new
local, it wouldn't produce the same results as ksh when assigning a
new value through the reference in the inner scope.

However, obviously that assignment also won't have the same result as
ksh after the inner scope returns, so zsh is going to differ somehow
no matter what.




Messages sorted by: Reverse Date, Date, Thread, Author