From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: PATCH: 4.1: multi-parameter for loop
Date: Thu, 21 Jun 2001 10:52:31 +0100 [thread overview]
Message-ID: <Tc0a88d0154470c687b@mailsweeper01.cambridgesiliconradio.com> (raw)
In-Reply-To: ""Andrej Borsenkow""'s message of "Thu, 21 Jun 2001 11:19:54 +0400." <001901c0fa22$91a2c6d0$21c9ca95@mow.siemens.ru>
"Andrej Borsenkow" wrote:
> 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?
This is covered in the manual page.
for p1 p2 in foo bar something else rubbish; do
print $p1 $p2
done
prints (I cut and pasted this from actually trying it out):
foo bar
something else
rubbish
and you get an empty string for the final $p2. I didn't thing there was
any point in doing too many sums --- particularly since you can use more
than two parameters; here's a way of naming a set of function arguments:
fn() {
local nam cmd val dsc
for nam cmd val dsc; do; break; done;
print "$nam, $cmd, $val, $dsc"
}
Then `fn Me nothing none dunno' prints `Me, nothing, none, dunno'.
With regard to `in', the standard interpretation is the one taken in all
the suggestions I've seen so far. I should make this clear in the manual,
though.
> bor@itsrm2% for i
> for> in a b c
> bor@itsrm2%
> ^^^^^^^^^^^^^^^ Oops!
That shouldn't be too hard to fix, and wouldn't affect the new syntax: we
just terminate the argument list at the end of the first line. Currently
it thinks the newline means you're not going to give an `in' and are using
positional parameters. I don't know why there's no syntax error, though,
but you get one if you set NO_SHORT_LOOPS.
> I guess, Bart suggestion (use foreach) is better. And more Perlish :-)
I'm not so convinced, since `for' and `foreach' currently do the same
thing, and I don't really like dividing the syntax to make people use the
non-standard variant just for one use. foreach is automatically handled at
the moment, as well as for, by the way.
> 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.
It's possible, but actually not that effective for hashes, since to iterate
through them they have to be flattened, and that only happens once in the
current system anyway.
By the way, I discovered a problem: alias expansion is turned on for
parameter names after the first;
alias h='history -f'
for g h in foo bar; do; done
turns `h' into `history -f' and the -f causes an unexpected parse error.
This is because of the csh-style syntax --- the shell is looking for a `('
which it needs to parse as a single token, so it uses the parsing rules for
command position. But now I know about it I can turn alias expansion off
explicitly for that bit.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
next prev parent reply other threads:[~2001-06-21 9:53 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
2001-06-21 9:52 ` Peter Stephenson [this message]
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=Tc0a88d0154470c687b@mailsweeper01.cambridgesiliconradio.com \
--to=pws@csr.com \
--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).