From: "Andrej Borsenkow" <Andrej.Borsenkow@mow.siemens.ru>
To: "Danek Duvall" <duvall@emufarm.org>,
"Zsh hackers list" <zsh-workers@sunsite.dk>
Subject: RE: PATCH: 4.1: multi-parameter for loop
Date: Thu, 21 Jun 2001 11:19:54 +0400 [thread overview]
Message-ID: <001901c0fa22$91a2c6d0$21c9ca95@mow.siemens.ru> (raw)
In-Reply-To: <20010620155622.A3447@lorien.emufarm.org>
>
> On Wed, Jun 20, 2001 at 08:12:09PM +0100, Peter Stephenson wrote:
>
> > "Bart Schaefer" wrote:
> > > Well, there's this:
> > >
> > > for in in in in; do echo $in; done
> >
> > It will stop reading parameters when it reaches the second
> `in'. I meant
> > to document this, although it should be pretty obvious.
>
> Right. That lacks ambiguity because multiple distinct parameters can't
> have the same name. But that ambiguity is missing in
>
> for i in in in; do ....
>
> Do you set $i to "in" and "in" or do you set $i and $in set to
> "in" and ""?
Which opens up a question of odd number of list elements. It is invalid in
assignment to hash - shuld it be invalid here as well?
> Posix presumably would simply use the first interpretation,
Yes. Here are grammar rules:
for_clause : For name linebreak do_group
| For name linebreak in wordlist sequential_sep do_group
name : NAME /* Apply rule 5 */
;
in : In /* Apply rule 6 */
5. [NAME in for]
When the TOKEN meets the requirements for a name (see name in the XBD
specification, Glossary ), the token identifier NAME will result.
Otherwise, the token WORD will be returned.
6. [Third word of for and case]
When the TOKEN is exactly the reserved word In, the token identifier for In
will result. Otherwise, the token WORD will be returned. (As indicated in
the grammar, a linebreak precedes the token In. If newline characters are
present at the indicated location, it is the token after them that is
treated in this fashion.)
Note linebreak here. Definition is:
linebreak : newline_list
| /* empty */
;
It means, that the following is valid:
fot i
in a b c
do
...
it is currently does not work in zsh:
bor@itsrm2% for i
for> in a b c
bor@itsrm2%
^^^^^^^^^^^^^^^ Oops!
as opposed to sh:
$ for i
> in a b c
> do
> echo $i
> done
a
b
c
and
> if you want
> something like the second, just don't use a parameter named in? Or am I
> missing the disambiguation?
>
I guess, Bart suggestion (use foreach) is better. And more Perlish :-)
Is there any feasible way to do something like
foreach key val hash
or even
foreach val array
i.e. do *not* expand $hash/%array value? For large arrays it may result in
significant speedup.
-andrej
next prev parent reply other threads:[~2001-06-21 7:20 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-06-20 14:45 Peter Stephenson
2001-06-20 16:11 ` Peter Stephenson
2001-06-20 18:01 ` Andrej Borsenkow
2001-06-20 18:20 ` Bart Schaefer
2001-06-20 18:39 ` Peter Stephenson
2001-06-20 18:55 ` Bart Schaefer
2001-06-20 19:12 ` Peter Stephenson
2001-06-20 22:56 ` Danek Duvall
2001-06-21 7:19 ` Andrej Borsenkow [this message]
2001-06-21 9:52 ` Peter Stephenson
2001-06-21 10:34 ` PATCH (redux): POSIX `for' syntax Bart Schaefer
2001-06-21 15:31 ` PATCH (redux): non-POSIX " Peter Stephenson
2001-06-25 16:05 ` Peter Stephenson
2001-06-21 9:55 ` PATCH: POSIX " Bart Schaefer
2001-06-22 6:29 ` PATCH: test case for " Andrej Borsenkow
2001-06-22 23:49 ` PATCH: 4.1: multi-parameter for loop Zefram
2001-06-23 0:04 ` Bart Schaefer
2001-06-21 8:33 ` Sven Wischnowsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='001901c0fa22$91a2c6d0$21c9ca95@mow.siemens.ru' \
--to=andrej.borsenkow@mow.siemens.ru \
--cc=duvall@emufarm.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).