From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 256E121302 for ; Fri, 29 Mar 2024 18:39:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Message-ID:Date:Content-ID: Content-Type:MIME-Version:Subject:To:References:From:In-reply-to:cc:Reply-To: Content-Transfer-Encoding:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=TslPkkifsyOOjz7OR0avicnK8kvSKzriuEzvBd6BexI=; b=ZAV52v5fCd6no4/eg5TA8FUb2i 4j/hx09O7WQahWtt2U91xAvMumDszHj22Gp+xtrHZWF5omEd/ceGm8CglpwqzVtKL0IEaKPBN4tcQ j3n1S2MnnwfbjOj5jO82JMcdTXQSDXVtv2p58b9pLwPQH7DW/ALiLJAi/iI7aINlKGH5ZlGsgsBSi L9rOkfmQ+yG3ZP6As8uuYMcX1ucUpKiv0TILXszy2YwRgybXE8VrBGmCYV9TgGioHyNgS2oXOuOYR 6De8DnRSw2Dy4+4CK1nSQg3FodDLmNx77peayqyQpuXw+3cxHK+A+OJbsMIR5SfDDcNw85skNIxko l0rLqVPg==; Received: by zero.zsh.org with local id 1rqGBx-000HhX-Jk; Fri, 29 Mar 2024 17:39:01 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rqGBi-000HOX-WC; Fri, 29 Mar 2024 17:38:48 +0000 Received: from [192.168.178.21] (helo=hydra) by mail.kiddle.eu with esmtp(Exim 4.97.1) (envelope-from ) id 1rqGBi-00000000BKG-0Hub; Fri, 29 Mar 2024 18:38:46 +0100 cc: Zsh hackers list In-reply-to: From: Oliver Kiddle References: To: Bart Schaefer Subject: Re: "break" and functions MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <43538.1711733926.1@hydra> Date: Fri, 29 Mar 2024 18:38:46 +0100 Message-ID: <43539-1711733926.063834@011r.oEGd.QZp_> X-Seq: 52850 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: Bart Schaefer wrote: > When adding this, I ran into a puzzling effect: > > % while :; do; echo ${|REPLY=x;break}; done > x > % while :; do; () { echo "$@" } ${|REPLY=x;break}; done > % > > That is, breaking the loop skips the function call but does not skip > the builtin. My expectation would have been for either an error message saying break: not in while, until, select, or repeat loop` or that because the break is run before the builtin that the builtin would never get to run. But the implementation of break is just putting a value in the breaks integer variable so I guess that variable isn't checked until after the builtin is run. The anonymous function is perhaps a two-stage process for defining and then running. Note: while :; do; () { echo hello } > ${|REPLY=x;break}; done creates an empty file named x. When suggesting the test, the exact behaviour was not something I cared strongly about provided it wasn't seg fault, infinite loop or similar. In the case of repeat 3 print c*(oe:'break':) it might be a useful feature if break applied to the internal loop over globbed files causing print to run but only with those files that were matched so far. false works as a continue in that case. If you're choosing which of the two cases in 52151 is wrong, I'd say that with the purr() function is right because the break is run before the print (or purr). And possibly, it should be an error message for "not in a while, ..." It also rather surprises me that the break here even works: br() { break } while : ; do br done Oliver