zsh-users
 help / color / mirror / code / Atom feed
* 5.1.1 available
@ 2015-09-11 18:18 Peter Stephenson
  2015-09-23 15:59 ` easy Ray Andrews
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2015-09-11 18:18 UTC (permalink / raw)
  To: Zsh Users

Version 5.1.1 of zsh is available at

http://www.zsh.org/pub/

This is mostly a fix for bugs discovered since 5.1, though a few minor
features have crept in.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* easy
  2015-09-11 18:18 5.1.1 available Peter Stephenson
@ 2015-09-23 15:59 ` Ray Andrews
  2015-09-23 19:45   ` easy Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Ray Andrews @ 2015-09-23 15:59 UTC (permalink / raw)
  To: zsh-users

When we do this:

     $ test () {  echo @[2,-1]; }
     $ test one two three four five
      two three four five

... why is it that the leading number works intuitively but the second one
is 'off by one' so to speak?  Nothing is removed from the end of the array
so one might expect " [2,-0] ".  I don't doubt there's a good reason but
what is it?  How should I think the syntax?


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

* Re: easy
  2015-09-23 15:59 ` easy Ray Andrews
@ 2015-09-23 19:45   ` Bart Schaefer
  2015-09-23 20:45     ` easy Ray Andrews
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2015-09-23 19:45 UTC (permalink / raw)
  To: zsh-users

On Sep 23,  8:59am, Ray Andrews wrote:
} Subject: easy
}
}      $ test () {  echo @[2,-1]; }

Presume you're missing a $ in $@ there ...

}      $ test one two three four five
}       two three four five
} 
} ... why is it that the leading number works intuitively but the second
} one is 'off by one' so to speak?

If you grasp that indexing from the left starts at one rather than
at zero, why is it not "intuitive" that indexing from the right also
starts at (negative) one rather than zero?

Note that there is no zero'th position in $* / $@ / $argv -- the use
of $0 as name of shell / script / function is just a convention.

(Unless you setopt ksharrays, but then $0 and ${argv[0]} are two very
different things, and even in ksh itself reverse index starts at -1.)

In any case mathematically +0 == -0 so if you think of them as array
positions those ought to refer to the same place (which in this case
is nothing, because there is no position zero).

Where you came up with thinking in terms of something being "removed
from the array" baffles me.  Nothing is "removed" from the original
array in either case; the indices identify what is *included* in the
result.

I suppose you're expecting ${argv[-1]} congruent with ${argv[$# - 1]}
and if ksharrays is set that works out to be true (but then $@[2] would
not mean what it does in your example, either).


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

* Re: easy
  2015-09-23 19:45   ` easy Bart Schaefer
@ 2015-09-23 20:45     ` Ray Andrews
  0 siblings, 0 replies; 4+ messages in thread
From: Ray Andrews @ 2015-09-23 20:45 UTC (permalink / raw)
  To: zsh-users

On 09/23/2015 12:45 PM, Bart Schaefer wrote:
> }      $ test () {  echo @[2,-1]; }
>
> Presume you're missing a $ in $@ there ...
Pardon.
> }      $ test one two three four five
> }       two three four five
> }
>
> If you grasp that indexing from the left starts at one rather than
> at zero, why is it not "intuitive" that indexing from the right also
> starts at (negative) one rather than zero?
Ah.  I was trying to make sense of it as 'subtract one element from the 
end'.  Which would
make more sense as 'subtract zero elements from the end' (in this 
case).  But as 'echo
from the second element from the left up to the first element from the 
right', then
'-1' is not a 'subtraction' rather it is the last element AKA the first 
element from the right.

Perfectly logical as I thought it would  be.  Tx.  Once you see the 
logic in something
you can never forget it cuz it makes sense, as that does.  Actually 
that's much
better anyway because both numbers are indices rather than one being an 
index
and one being a mathematical operation.  Just hafta remember that the dash
does not mean subtraction, rather it means index from the right.





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

end of thread, other threads:[~2015-09-23 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-11 18:18 5.1.1 available Peter Stephenson
2015-09-23 15:59 ` easy Ray Andrews
2015-09-23 19:45   ` easy Bart Schaefer
2015-09-23 20:45     ` easy 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).