Re: String?
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 02, 2004
- 644 views
On 2 Jun 2004 11:47:25 +0200, Christian Cuvier <Christian.CUVIER at agriculture.gouv.fr> wrote: >}}} <eucode> > >--find first pair of adjacent distinct values: >p=find(0,(s&s[length(s)] = prepend(s,s[1]))-1 -- -1 if no such pair There is a syntax error in that, and even if I fix it a simple for loop is about twice as fast when s={1,1,1,1,1,1,1,1,1,2} >--find first repeated value: >p=find(1,(s&s[length(s)] = prepend(s,s[1]))-1 -- -1 if no such pair Another syntax error, and that does not work at all. If I fix it so it does, a for loop is still twice as fast when s={1,2,3,4,5,6,7,7,8,9} >--find first mismatch: >p=find(0,(s1 = s2)) That one, OK, I grant you is slightly faster. and somewhat easier to type. You could still code it as p=find(0,eq(s1,s2)) though, provided there was a new builtin eq() function to replace the sequence op.. >--is a sequence strictly increasing? >p=find(1,(s&(s[length(s)]+1) >= prepend(s,s[1]-1)) --0 means yes Again, a simple for loop is over twice as fast. > ></eucode> {{{ > >Could go on for pages. These operators are quite useful in conjunction with >find(). match() allows even niftier tricks. Well, now that I have just tested them, I know they are not as fast as people like to think they are, and they can easily be replaced with a builtin function. Pete