From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: From: erik quanstrom Date: Thu, 8 Mar 2007 23:38:03 -0500 To: 9fans@cse.psu.edu Subject: Re: [9fans] How can I shift a variable other than ? MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-ghoqyoomoocujjtucddrcuxmxp" Topicbox-Message-UUID: 1cbc8af8-ead2-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-ghoqyoomoocujjtucddrcuxmxp Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit ... or the deleterious effects of insomnia. i decided to see how hard this is. after considering "shift var", and hd and tl, i added ranges to rc, as in cpu% 8.out broken! a=(1 2 3 4) broken! echo $a(1 4) 1 4 broken! echo $a(2-3) 2 3 broken! echo $a(2-) 2 3 4 broken! fn myshift{echo $*; '*' = $*(2-) ; echo $*} broken! myshift 1 2 3 4 5 1 2 3 4 5 less than 20 lines of code. (attached so you can avert your eyes.) - erik --upas-ghoqyoomoocujjtucddrcuxmxp Content-Disposition: attachment; filename=snippit Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit word* copynwords(word *a, word *tail, int n) { word *v = 0, **end; for(end=&v;a && n-- != 0;a = a->next,end=&(*end)->next) *end = newword(a->word, 0); *end = tail; return v; } word* subwords(word *val, int len, word *sub, word *a) { int n, m; char *s; if(!sub) return a; s = sub->word; deglob(s); a = subwords(val, len, sub->next, a); n = 0; m = 0; while('0'<=*s && *s<='9') n = n*10+ *s++ -'0'; if(*s++ == '-'){ if(*s) while('0'<=*s && *s<='9') m = m*10+ *s++ -'0'; else m = len; m -= n; } if(n<1 || lennext; return copynwords(val, a, m+1); } --upas-ghoqyoomoocujjtucddrcuxmxp--