From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from skinner.cs.wisc.edu ([128.105.1.19]) by archone.tamu.edu with SMTP id <18921>; Thu, 19 Dec 1991 19:50:01 -0600 From: dws@cs.wisc.edu (DaviD W. Sanderson) Message-Id: <9112200140.AA20484@skinner.cs.wisc.edu> Received: by skinner.cs.wisc.edu; Thu, 19 Dec 91 19:40:37 -0600 Subject: new fn index To: rc@archone.tamu.edu Date: Thu, 19 Dec 1991 19:40:36 -0600 X-Mailer: ELM [version 2.3 PL11] 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