zsh-users
 help / color / mirror / code / Atom feed
* unshift
@ 2024-04-01 13:52 Ray Andrews
  2024-04-01 13:54 ` unshift Mark J. Reed
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Ray Andrews @ 2024-04-01 13:52 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1872 bytes --]

Can we unshift the positional params?  I have a complex function that 
has shifts throughout and at one point there's a while loop:

shift
while [ "$1" ]; do
     if [ a ]; then b; c  fi
     if [ d ]; then e; f  fi
     if [ g ]; then h; i  fi
...
shift
done

... works fine, but I'm thinking to restructure it:

shift
while [ "$1" ]; do
     if [ a ]; then b; c; continue fi
     if [ d ]; then e; f; continue fi
     if [ g ]; then h; i; continue fi
...
shift
done

... because only one 'if' test will be relevant per loop and the 
remaining 'if' tests might even do some bad stuff.  The problem of 
course is that if I 'continue', the final 'shift' is missed.  I could do 
this:

# shift
while [ "$2" ]; do
     shift
     if [ a ]; then b; c; continue fi
     if [ d ]; then e; f; continue fi
     if [ g ]; then h; i; continue fi
...
# shift
done

... except that the leading (commented) 'shift' might happen in any 
number of places and changing them all would be troublesome.  It can be 
done of course, but I'm wondering if we have some way of  faking this:

shift
unshift
while [ "$1" ]; do
     shift
     if [ a ]; then b; c; continue fi
     if [ d ]; then e; f; continue fi
     if [ g ]; then h; i; continue fi
...
# shift
done

... it looks pointless above, however note that the leading 'shift' 
might in fact have happened in any one of several different places all 
of which would need to be reworked and it's fragile, so the 'unshift' 
would take care of it in one place, at least temporarily.  I know we 
don't have an official unshift, but can it be faked?  Of course there's 
also this:

     ...
     if [ a ]; then b; c; shift; continue fi
     ...

... but I'm wondering about a more succinct logic.  The quick and dirty 
'unshift' idea would solve a temporary problem very nicely.



[-- Attachment #2: Type: text/html, Size: 2880 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-04-02 20:24 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 13:52 unshift Ray Andrews
2024-04-01 13:54 ` unshift Mark J. Reed
2024-04-01 14:00   ` unshift Mark J. Reed
2024-04-01 14:23   ` unshift Ray Andrews
2024-04-01 16:03   ` unshift Stephane Chazelas
2024-04-01 14:38 ` unshift Roman Perepelitsa
2024-04-01 16:11   ` unshift Ray Andrews
2024-04-01 16:20     ` unshift Roman Perepelitsa
2024-04-01 16:40       ` unshift Ray Andrews
2024-04-01 19:41         ` unshift Bart Schaefer
2024-04-01 22:52           ` unshift Ray Andrews
2024-04-01 16:03 ` unshift Bart Schaefer
2024-04-01 16:30   ` unshift Ray Andrews
2024-04-02 12:41 ` unshift Dennis Eriksen
2024-04-02 14:01   ` unshift Ray Andrews
2024-04-02 19:59     ` unshift Roman Perepelitsa
2024-04-02 20:24       ` unshift Ray Andrews

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).