zsh-workers
 help / color / mirror / code / Atom feed
* recursive function warnings ...
@ 1996-09-11  6:37 Duncan Sargeant
  1996-09-11 19:49 ` Zoltan Hidvegi
  0 siblings, 1 reply; 2+ messages in thread
From: Duncan Sargeant @ 1996-09-11  6:37 UTC (permalink / raw)
  To: zsh-workers


The one mistake I've made a few times now is that when I write a
function to replace a command, and then call that command from
within the function, I often get an error which usually means
nothing to me, and its a while before I find out what I did wrong.

Usually its because of something as in the following example:

function finger {
  if [[ $* == "*@*" ]] then
    finger $*
  else
    finger ${*}@ucc
  fi
}

which recursively call the _function_ finger because I, cluelessly,
have not specified a pathname (er derr).  Looks easy to remember but
its not the first time I've done it.  And I doubt it'll be the
last.

Of course something like:

function finger {
  if [[ $* == "*@*" ]] then
    /usr/bin/finger $*
  else
    /usr/bin/finger ${*}@ucc
  fi
}

is far more appropriate and what I wanted.

anyway, I was just wondering about the possibility of an option or
something so that if a function calls itself recursively, a warning
message is printed, eg:

Warning: function finger calls itself recursively.

then maybe to stop this annoying message occurring again, one
specifies the function with the -r option, eg
function -r finger { ...  
just in case the function needs to call itself recursively.

that would be really cool, if anyone can be bothered.



-- 
Duncan Sargeant, http://www.ucc.gu.uwa.edu.au/~dunc/
The older a father gets, the farther he had to walk to school.


PS: I'm not on zsh-workers myself ... only zsh-users, so I won't
get any reply sent only to zsh-workers.

PPS: why did I want such a function.  Well the finger command on
one machine in our domain is still the stock standard finger,
whereas we use a global finger for all our machines, so that 
finger @ucc.gu.uwa.edu.au lists all users on all machines.
Try it, if you like!
anyway the function fingers @ucc if no @ is in the options.
if @ is there eg foo@bar.net then it'll not finger ucc.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: recursive function warnings ...
  1996-09-11  6:37 recursive function warnings Duncan Sargeant
@ 1996-09-11 19:49 ` Zoltan Hidvegi
  0 siblings, 0 replies; 2+ messages in thread
From: Zoltan Hidvegi @ 1996-09-11 19:49 UTC (permalink / raw)
  To: Duncan Sargeant; +Cc: zsh-workers

> anyway, I was just wondering about the possibility of an option or
> something so that if a function calls itself recursively, a warning
> message is printed, eg:
> 
> Warning: function finger calls itself recursively.
> 
> then maybe to stop this annoying message occurring again, one
> specifies the function with the -r option, eg
> function -r finger { ...  
> just in case the function needs to call itself recursively.

But there are real shell functions which use recursion.  Adding this
feature would break them.

Note that you can always use `command finger' to invoke the finger external
command without knowing the exact pathname.

Zoli


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1996-09-12  3:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-09-11  6:37 recursive function warnings Duncan Sargeant
1996-09-11 19:49 ` Zoltan Hidvegi

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).