zsh-users
 help / color / mirror / code / Atom feed
* zshexpn problem
@ 2005-02-20  4:33 Matthias Berndt
  2005-02-20  5:07 ` Matthias Berndt
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Berndt @ 2005-02-20  4:33 UTC (permalink / raw)
  To: zsh-users

Hi,

When LVERSION=2.6.10 ... why:

print ${(s/./)LVERSION[1]}
-> 2
print ${(s/./)LVERSION[2]}
->
print ${(s/./)LVERSION[3]}
-> 6
print ${(s/./)LVERSION[4]}
->
print ${(s/./)LVERSION[5]}
-> 1
print ${(s/./)LVERSION[6]}
-> 0

... and not ...

print ${(s/./)LVERSION[3]}
-> 2
print ${(s/./)LVERSION[3]}
-> 6
print ${(s/./)LVERSION[3]}
-> 10

Something like ...

print ${${(s/./)LVERSION}[1]}
-> 2
print ${${(s/./)LVERSION}[1]}
-> 6
print ${${(s/./)LVERSION}[1]}
-> 10

... works 'correct', but is seems not very intelligent.


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

* Re: zshexpn problem
  2005-02-20  4:33 zshexpn problem Matthias Berndt
@ 2005-02-20  5:07 ` Matthias Berndt
  2005-02-21 12:04   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Berndt @ 2005-02-20  5:07 UTC (permalink / raw)
  To: zsh-users

On Sun, 20 Feb 2005 05:33:35 +0100
Matthias Berndt <Berndt.Matthias@gmx.de> wrote:

> Hi,
> 
> When LVERSION=2.6.10 ... why:
> 
> print ${(s/./)LVERSION[1]}
> -> 2
> print ${(s/./)LVERSION[2]}
> ->
> print ${(s/./)LVERSION[3]}
> -> 6
> print ${(s/./)LVERSION[4]}
> ->
> print ${(s/./)LVERSION[5]}
> -> 1
> print ${(s/./)LVERSION[6]}
> -> 0
> 
> ... and not ...
> 
> print ${(s/./)LVERSION[1]}
> -> 2
> print ${(s/./)LVERSION[2]}
> -> 6
> print ${(s/./)LVERSION[3]}
> -> 10
> 
> Something like ...
> 
> print ${${(s/./)LVERSION}[1]}
> -> 2
> print ${${(s/./)LVERSION}[2]}
> -> 6
> print ${${(s/./)LVERSION}[3]}
> -> 10
> 
> ... works 'correct', but is seems not very intelligent.
> 

Sorry, shit happens' when copy 'n paste. Now the values are correct.


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

* Re: zshexpn problem
  2005-02-20  5:07 ` Matthias Berndt
@ 2005-02-21 12:04   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2005-02-21 12:04 UTC (permalink / raw)
  To: zsh-users

Matthias Berndt wrote:
> On Sun, 20 Feb 2005 05:33:35 +0100
> Matthias Berndt <Berndt.Matthias@gmx.de> wrote:
> 
> > Hi,
> > 
> > When LVERSION=2.6.10 ... why:
> > print ${(s/./)LVERSION[2]}
> > ->

The s splitting happens late; it means the overall result of the
expansion is an array.  It doesn't mean the value is instantly turned
into an array.  (It's not evaluated simply left to right, for example.)

There are a list of rules in the manual page for the order in which an
expansion takes place at each level of nesting, and they have this order:

2. _Parameter Subscripting_
  i.e. the [2]
8. _Forced Splitting_
  i.e. the (s/./)

So actually it's not well defined what happens in this case.

Obviously, "documented" isn't the same as "clear".  The following sentence
is the key part of the documentation:

  Note that the Zsh Development Group accepts _no responsibility_ for any
  brain damage which may occur during the reading of the following rules.

> > print ${${(s/./)LVERSION}[2]}
> > -> 6
> > 
> > ... works 'correct', but is seems not very intelligent.

That's the correct, logical way to do it, in as much as zsh is ever
logical.  Generate an expression which returns an array, then apply the
subscript to that.  Then rule 1 comes into force.

1. _Nested Substitution_
     If multiple nested ${...} forms are present, substitution is
     performed from the inside outwards.  At each level, the
     substitution takes account of whether the current value is a
     scalar or an array, whether the whole substitution is in double
     quotes, and what flags are supplied to the current level of
     substitution, just as if the nested substitution were the
     outermost.
     ...

I still marvel that people complain about Perl being obscure.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************


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

end of thread, other threads:[~2005-02-21 12:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-20  4:33 zshexpn problem Matthias Berndt
2005-02-20  5:07 ` Matthias Berndt
2005-02-21 12:04   ` Peter Stephenson

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