Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: subscript expanded twice in a[subcript]++ (Was: problem with RANDOM and arrays)
- X-seq: zsh-workers 27613
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: subscript expanded twice in a[subcript]++ (Was: problem with RANDOM and arrays)
- Date: Wed, 20 Jan 2010 10:28:14 -0800
- In-reply-to: <20100120164648.7c23769f@news01>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <chaz20100111201312.GB3902@xxxxxxxxxxx> <chaz20100120133218.GB3872@xxxxxxxx> <20100120164648.7c23769f@news01>
On Jan 20, 4:46pm, Peter Stephenson wrote:
}
} Had an idea... the second level down in the parameter code contains the
} evaluated subscript, so we can cache that, and be as paranoid as we feel
} about the validity of the cached value.
Much better:
schaefer<503> x=0; a=(x+=3 x+=2 x+=1 x+=4 x+=5); ((++a[++x])); print $a $x
5 x+=2 x+=1 x+=4 x+=5 4
Still a little dicey, but probably not fixable:
schaefer<507> x=3; a=(x+=3 x+=2 x+=1 x+=4 x+=5); ((++a[++a[1]])); print $a $x
7 x+=2 x+=1 x+=4 x+=5 1 6
In that expression, we read a[1] and get (x+=3) so we increment a[1] as
(x+=3+1)=7 and then increment a[7] (which was previously unset) to get 1.
There's probably some really complicated side-effect threading you could
get going with this.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author