Am 06.06.2018 um 01:38 schrieb Kenny McCormack:
>> [ functions with named parameters and value result ]
>
> I seem to have a vague memory that some version(s) of ksh did this, and,
> frankly, I'm surprised that Janis (who seems to be really in a**hole mode
> for this thread) hasn't mentioned it yet. Of course, my memory could be
> wrong.
If I'd be aware of such a thing I would of course have told you about it
in my previous reply. I've used ksh (ksh88/ksh93) for decades, and also
observed its evolution. To my best knowledge there wasn't such a thing
ever in original ksh. (It's of course possible that some ksh-like shell
clone might have incorporated such functions; I wouldn't know.) For the
original ksh I'm positive that you are misremembering.
As I already mentioned in my previous reply ksh *has* done significant
extensions to shell functions. Most prominent was inventing "Kornshell
functions"; functions that behave like complete shell scripts (WRT
option- and signal-handling, local variable definitions, maybe more).
Then there's the discipline functions; (to explain it only roughly)
functions that get triggered when function-associated variables are
handled. Ksh has also introduced the arithmetic command, something at
least related to (numeric) functions. And in context of ksh functions
the name-references for function parameters (where I gave an example
in my previous post). Last but not least there's the "object-oriented"
(an imperfect term, can't find a better one at the moment) extensions.
That's off the top of my head all that I recall in context of ksh and
function related issues.
I'd also like to re-emphasize that functions (in shell) are a misnomer;
they are (in Pascal terminology) more like "procedures". A term like
"command definition" would probably have fit better; "function" is very
misleading (as your post seems to show as well). In Unix/shell context
it makes sense that these "command definitions" behave as they do -
returning error codes through an implicit channel -, and don't resemble
mathematical functions. (But the misnomer is certainly unfortunate.)
One could think about an extension with an own syntax for functions
with named parameters and value result. But that would need an own
syntactical context (similar as arithmetic has $((...)) and ((...)) ).
The current shell design would make that hard, though; arithmetic is
bound to these parenthesized expressions, string handling is bound to
variable expansion mechanisms; now having functions like in awk would
not fit well in the shells' syntactical frame.
I guess we have to bite the bullet and use the existing mechanisms
with programming patterns that alleviate the "ugly" shell syntax.
(I posted an example in my previous post.) If one is doing heavy
"functional" programming it's probably better to switch to another
language than shell, or separate the tasks and combine the tools.
Janis