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

Re: zmv exits from function



On Sun, Dec 31, 2023 at 5:07 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:

On 2023-12-31 13:44, Bart Schaefer wrote:
> On Sun, Dec 31, 2023 at 7:53 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>> So that's multi-pass parsing.
> Again, no.  It's only parsed once

I don't have the background to understand it and it's probably not worth
your time to make it clear.  

It's not parsed multiple times, but it _is parsed fully before anything runs.  _Parsing_ is just reading the code and determining what it means; actually _running_ it comes later. Zsh parses the whole _expression_ before it executes any part of it – it doesn't just stop and execute the first thing that looks like a command. So it has already read the `always` block and knows it's there before it executes the code to the left of it. 

And the presence of the `always` doesn't affect parsing; the code on both sides works the same way it would without the `always`. The only thing it does is tell Zsh that, as long as the code on the left doesn't exit the shell entirely, it doesn't matter what happens there; the code on the right needs to get executed next. Even if the left code interrupts the normal control flow with a `return` or `break` or `continue`, the code on the right will get executed before the next thing, wherever that next thing is.

--
Mark J. Reed <markjreed@xxxxxxxxx>


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