zsh-workers
 help / color / mirror / code / Atom feed
From: Duncan Sargeant <dunc@ucc.gu.uwa.edu.au>
To: zsh-workers@math.gatech.edu
Subject: recursive function warnings ...
Date: Wed, 11 Sep 1996 14:37:09 +0800 (WST)	[thread overview]
Message-ID: <199609110637.OAA02883@mermaid.ucc.gu.uwa.edu.au> (raw)


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.


             reply	other threads:[~1996-09-11  6:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-11  6:37 Duncan Sargeant [this message]
1996-09-11 19:49 ` Zoltan Hidvegi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199609110637.OAA02883@mermaid.ucc.gu.uwa.edu.au \
    --to=dunc@ucc.gu.uwa.edu.au \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).