On 2016-01-25,
Joerg.S...@fokus.fraunhofer.de <
Joerg.S...@fokus.fraunhofer.de> wrote:
> In article <cch6nc-...@chris.tor>,
> Chris F.A. Johnson <
newsg...@cfaj.ca> wrote:
>>On 2016-01-21, Hongyi Zhao wrote:
>>> Hi all,
>>>
>>> I want to define the following alias:
>>
>>man bash:
>> "For almost every purpose, aliases are superseded by shell functions."
>
> This is just a man page from a shell that does not implement a method to
> support parameterized macros.
>
> Shell functions have the pitfall that they are listed when you call "set".
This is somewhat of a misfeature of "set". The shell effectively has two
namespaces, like Common Lisp. You can have a function called foo, and a
variable called foo. Yet, "set" spews both namespaces.
What is worse, though, is that "unset" removes from both---but one at a
time (at least in Bash).
> Modern versions of the Bourne Shell include a builtin command called "dosh"
> that allows to implement one-line shell scripts with an own set of $* ($@)
> parameters. The concept is from the "UNOS" command shell from 1980.
>
> You could e.g. have a "lm" alias that expands to:
>
> dosh 'ls -l "$@" | more' lm
>
> and then e.g. type:
>
> lm *.c
This doesn't seem like progress over:
$ lm() { ls -l "$@" | more; }
$ lm *.c
> The advantage of this concept is that you only have definitions in the
> cleanly separated alias namespace
It isn't entirely separated, because a symbol in the leftmost position
of the command line could potentially be a function or alias (or builtin
or external). So at dispatch time, at least, the two namespaces
come together. If foo is both an alias an a function, the shell has to
work out which is invoked by "foo arg ...".
The problem with "set" you describe could be fixed by providing
alternative commands for listing the namespaces, and for unbinding
functions and variables.
For instance "lsvar" could list variables, "lsfun" could list functions,
"unbind x" could remove variable x (like Lisp's makunbound), "funbind x"
could remove function x.
Bash has solved this problem with options on "unset":
unset -v foo # unset in variable namespace
unset -f foo # unset in function namespace
The fact that set lists everything is moot; nobody ever does that
other than interactively.
Bringing in yet another namespace just because "set" doesn't work the
way you want seems really a poor design approach. Fix or replace that
which is broken, directly.
> implemented via a
> single builtin program instead via one specific shell function.
What does that mean and why would anyone care?
If you write multiple shell functions, they are dispatched and
interpreted through the same built-in mechanism.
If you write multiple dosh aliases, same thing: multiple definitions
are dispatched through the same dosh-alias-dispatching mechanism.