Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parse error (lack thereof) on incomplete loops
- X-seq: zsh-workers 43607
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: Parse error (lack thereof) on incomplete loops
- Date: Fri, 5 Oct 2018 10:14:33 +0100
- Cms-type: 201P
- Dkim-filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20181005091436euoutp02eead600dee6ac1834f56108dc3a94822~aq5RzH5gc0339303393euoutp02N
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1538730876; bh=jG3Kex1Q7n8omiLzAjsZ9Sp7mrPLlPqp8WiR5JcZ2Ks=; h=Subject:From:To:Date:In-Reply-To:References:From; b=YbyA3/r5pfbXFWZvf5P/e1zHViYBNaydeE2Ddh06COHiPEzuE1SMChE4u/+hV8mhJ 62+Myjy6OX06FKsXkoLl8MShqGpJCmjyQoM3g/PdRNmQypbCsHL94gS3vvkdk5LpVY WzTM/f5NE6ofUZJrTDC77Qafeb55Uqo5DdC6sxos=
- In-reply-to: <CAH+w=7ZLJ5iiph8jpsSiLKdhkozqH+o_kJk7=zfK3DLBegft8g@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20181004154947epcas4p2441e109a2c4e060bf39f0f6925e98241@epcas4p2.samsung.com> <CAH+w=7awbwDuX2RXcB7pK6Hhbi8fjs=NvwkTAEGmY7gvNpLCqA@mail.gmail.com> <20181004163158eucas1p234a045be013b5463d8db44314ed217dc~adN28lJmq0822408224eucas1p2F@eucas1p2.samsung.com> <CAH+w=7ZLJ5iiph8jpsSiLKdhkozqH+o_kJk7=zfK3DLBegft8g@mail.gmail.com>
On Thu, 2018-10-04 at 13:34 -0700, Bart Schaefer wrote:
> My problem with it is that it's not consistent.
>
> set -x
> { while false
> while false
> }
>
> The shell is now in an infinite loop executing "false". Can this
> really be intentional?
What's happening here is to do with
while false; do
print Never executed
done
print $?
This prints 0. So the body of the last "while false" is actually
irrelevant.
The original expression is parsed as
{
while {
false
while false; do
done
}; do
done
}
which is an infinite loop because of the point above. Or, in other
words, it's the same as
{
while false
true
}
This also used to give a parse error for the same reason. However,
apart from that there's nothing new --- you can see that even with
NO_SHORT_LOOPS,
while false; true; do print Looping; done
(where that "true" could be a "while false" loop, if you like) has been
an infinite loop since way back when. The only new feature is that all
the "do ... done" clause has become optional if it's possible to infer
there's nothing there. That seems to me entirely consistent.
Without a "do" while doesn't know where the expression ends. That's
fundamental to how SHORT_LOOPS works and why I regard it as so
ill-defined as to be useless in all but the simplest cases. This new
(accidental) feature is giving it a particularly straightforward way of
telling it where the expression ends.
Anyway, I'm perfectly happy either restoring the parse error or not,
depending on the opinions of people more likely to use or fall foul of
this kind of syntax but I don't think the reason "it's all a bit weird"
is good enough on its own for restoring it. Short loops *are* weird.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author