Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: N=5 echo $[N-1] why doesn't it work as expected
- X-seq: zsh-users 14240
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: N=5 echo $[N-1] why doesn't it work as expected
- Date: Fri, 17 Jul 2009 21:27:04 +0100
- In-reply-to: <200907171001.n6HA1L00032510@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <tkrat.e1ca3b460deca95d@xxxxxxxxxxxxxxxxxxx> <20090717073915.GA15461@xxxxxxx> <20090717100656.535be86b@news01> <237967ef0907170232p5abaddebw891f9b7bca1476ab@xxxxxxxxxxxxxx> <200907171001.n6HA1L00032510@xxxxxxxxxxxxxx>
On Fri, 17 Jul 2009 11:01:21 +0100
Peter Stephenson <pws@xxxxxxx> wrote:
> % N=5 fn() { echo $N; }
> % which fn
> fn not found
This makes it consistent with other non-trivial structures (and the
documentation), disallowing assignments in front.
Of course, the whole point of anonymous functions is that you have
ordinary local variables, which are much more flexible:
% () { local N=8; print I\'m in an anonymous function with N=$N; }
I'm in an anonymous function with N=8
Index: Src/parse.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/parse.c,v
retrieving revision 1.80
diff -u -r1.80 parse.c
--- Src/parse.c 6 Jul 2009 20:44:29 -0000 1.80
+++ Src/parse.c 17 Jul 2009 20:22:47 -0000
@@ -1546,7 +1546,7 @@
par_simple(int *complex, int nr)
{
int oecused = ecused, isnull = 1, r, argc = 0, p, isfunc = 0, sr = 0;
- int c = *complex, nrediradd;
+ int c = *complex, nrediradd, assignments = 0;
r = ecused;
for (;;) {
@@ -1586,6 +1586,7 @@
ecstr(name);
ecstr(str);
isnull = 0;
+ assignments = 1;
} else if (tok == ENVARRAY) {
int oldcmdpos = incmdpos, n, type2;
@@ -1606,6 +1607,7 @@
YYERROR(oecused);
incmdpos = oldcmdpos;
isnull = 0;
+ assignments = 1;
} else
break;
zshlex();
@@ -1667,8 +1669,12 @@
zlong oldlineno = lineno;
int onp, so, oecssub = ecssub;
+ /* Error if too many function definitions at once */
if (!isset(MULTIFUNCDEF) && argc > 1)
YYERROR(oecused);
+ /* Error if preceding assignments */
+ if (assignments)
+ YYERROR(oecused);
*complex = c;
lineno = 0;
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author