From: dws@cs.wisc.edu (DaviD W. Sanderson)
To: rc@archone.tamu.edu
Subject: new fn index
Date: Thu, 19 Dec 1991 19:40:36 -0600 [thread overview]
Message-ID: <9112200140.AA20484@skinner.cs.wisc.edu> (raw)
Well, I stuck out my neck and Chris showed me how to eliminate
even the one use of an external command. That'll teach me! :-)
#-------
# index - print the index of the given string in the given list.
# (0 if not there)
# If the string occurs more than once, the index of the last occurrence
# is printed.
#-------
fn index { # str list
str = $1 ans = () {
shift
while(~ $str $*)
{
#-------
# count in unary
# May as well keep track of what I'm shifting
# (perhaps it will be useful in a different
# version...).
#-------
ans=($ans $1)
shift
}
echo $#ans
}
}
index a (x y z) # 0
index a (a y z) # 1
index a (x a z) # 2
index a (ax y a) # 3
index '' (a '' b '') # 4
next reply other threads:[~1991-12-20 1:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1991-12-20 1:40 DaviD W. Sanderson [this message]
1991-12-20 2:17 Tom Culliton x2278
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=9112200140.AA20484@skinner.cs.wisc.edu \
--to=dws@cs.wisc.edu \
--cc=rc@archone.tamu.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.
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).