bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem anomalies , possibly aliases related


From: Martin D Kealey
Subject: Re: problem anomalies , possibly aliases related
Date: Fri, 21 Jul 2023 00:33:07 +1000

On Thu, 20 Jul 2023, 23:28 Greg Wooledge, <greg@wooledge.org> wrote:

> The idea that this would "work" is quite surprising to me.


Shell functions are SO unlike functions in other languages that it
surprises me that anyone would assume any particular parallel holds.

Everything about them is dynamic: where they find variables (up frame by
default unless you use "local"); even their very existence, which only
begins when the flow of control passes over their definitions, and ends
with unset -f.

So when one reads the manual and it says "outer loop", there is no reason
to assume this is referring to grammatical scope; dynamic scope makes just
as much sense, and a quick test confirms it. Well, it DID confirm it.

The basic idea of a function is that it does stuff and then returns you to
> the point where you were when the function was called.
>

Except that it's not (at least, not since we mangled the mathematical word
"function" to mean what we used to call "subroutine").

C has longjmp, and other languages have exceptions. Non-local break is a
usable "Bash shaped" analogue of those. Not perfect, sure, but close enough
to be useful. (Non-local continue is a logical extension of that.)

Saying that this *ought* to be done using aliases is not reasonable, as it
means forgoing the other stuff that functions can do, like taking
parameters, declaring local variables, or returning a status.

-Martin


reply via email to

[Prev in Thread] Current Thread [Next in Thread]