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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,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 B87E121351 for ; Fri, 29 Mar 2024 19:51:35 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1711738295; b=INB1nTlF6nWk4WX2RVXGkQ7PDN1EiEHA58VzRGC4p9dDEP6MmtOy9N+TqaYqgv1hT9VyLL9PPC hcmUhV1WFp79qXDHVTifn6CY4N+sbe/ITt/SmSNFR4dHzfTjwTnoAo91e3Y+N5Nx+QBe1bFxZh f5lc6Wv4qIiUcxABUYF8JP0pirgqn0I57tmKG+dLeAs1da1cPI+QxnnP2Tl9dA4idJWrtp6n5F BKu6cOjYgNNBUq7saGwgzA5f5cwqccXznnBdNfuNgxg6wXoxNRQ+DWb/VY3xOprprCrW6tQdMo wjMD9BmNA5E23gHUvWpbrsM1H7KJUyBE7tUI4rueLGEUZQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f42.google.com) smtp.remote-ip=209.85.208.42; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1711738295; bh=dOsIU7HluzCb1/FonyfJXC1Q5ZKURrCUmxAJvGYM+8A=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=q8pypVy+o2zdieKGU292Co3uVyRbcF8iW/a1/sTQSoLNEr/tZIQPdF1U5mlOrz0LzhgTXb67lc Pv1nLruOVQZDCZSRGwju3CAnvPBo5otqh/mJo27jMYiOaVIfFo8iRAjf8NVYVHmG5okgs4YLqB d0RTpVRAsIxRvPd7XhiEe3DtIQLB0X4EcOdzvcwGFLhY6ZCZEsBxIYnHFm7bSoffAKWDhn6kpm 1aXZSP6c526lwhlg8P8pPwuNWK/EtNIubFHDKKQ05iWvktoT01xH31k6o9+aHFvAfYqY4vWMI4 pfnmId3J1a6I4iO3QoP5OfnEz3HyxatGj9ufByTVA7OJ4A==; 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:Content-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=FzGjK7o7wfN3H5MQ85lAc52w+KhJ3qmJCbZduG0JQZA=; b=PMM72+V3z99K7eTGZhuHpA+Lcc uQUngTvLhQkBi+RBvGcohXGc+Vi5ib8xuLhTMhrsLyozu3MQaOZ7pmcrWGq1AgWyutZrhr3Z9umps YD/aWh8uK0n5S4unwzj0ZLlPxtzZlhgXPL6TNsfXWW6OKc3HQUmTt3/ZsW7xZ/1/v8C75LNaGRUnR UiYRSkJFdH6IyYLaDq1wtdGxmrt2/CVv6Yn1jIFCkmHmmjtGgrj0sY+EUR0AEWbc5rPusc1kg/VDK 0k5A/xWe6Nn6S1EkC7KnkJ+/wLisk6wvV8zzAyiVu9faOTEwHIFF+qXQf9AoH819mHydfm6QhrAgi CLIL74+A==; Received: by zero.zsh.org with local id 1rqHKA-000Kgb-2d; Fri, 29 Mar 2024 18:51:34 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f42.google.com) smtp.remote-ip=209.85.208.42; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f42.google.com ([209.85.208.42]:55660) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rqHJr-000KNN-Rp; Fri, 29 Mar 2024 18:51:16 +0000 Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56d5d4d2e2bso693771a12.3 for ; Fri, 29 Mar 2024 11:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1711738275; x=1712343075; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FzGjK7o7wfN3H5MQ85lAc52w+KhJ3qmJCbZduG0JQZA=; b=qocX3szLU2rYvAel+qVwqfIoPGbpmIig+nYaz6jtFqEgVuIi9drIbLGDSQMoEYT23Z yao9o4T1KBj1p+iAvJLF/k7pGhPpEjtg1b+9B3zfrUWkQVVpol02j6cfTd0EcK3suxAe /ZIrq5syL2irEAqcQhEuZYvblvG+wNQ1Fl+E2L41GNP/L2k2BnDL5kMscfOAliLMCLmC GjHCK6c2pBYU86XD8KgUYYELJ39+R7Qn38EAY3oo964u1Tyv+UurR/tdm8sDuYibobJZ O+xVbvjktgBlWRpYg/RTJo0TgmCfdS7qgb9FRKCinFCiYWqnwDfiDxyMvipBHaH31mK7 fIkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711738275; x=1712343075; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzGjK7o7wfN3H5MQ85lAc52w+KhJ3qmJCbZduG0JQZA=; b=rhbY/WUKwgXKLetLokM92KyUlEVTC4w25cKkfHDD+/NkRiyJbQww6vnUj1hnQdSsVg fEsBZE197SD2c2ynS5Fq0WtraAE412NubA0KwFZ5ZTTplOj7glUqjU0qxQgUeCN9r7pr 5hnzxgc3esVFlFnrhw5jaFWvmi4D9CnOu4zDG2YjQLWFtiZfUH2uTWMgFia0o8qjVePf A67xOL5gs7yL5dRRHWU/sVoDkyKt5/k8wdZtn57U2Q2w6mFrXMceFRUZZH0iduy9WFw5 7MTsNnBjepBc1PnoCUIE7rph2deOMA2cQukqqhAF6PX3zWjf9enH/lRPb9D+xa7EiXjY r67w== X-Gm-Message-State: AOJu0YyeEPMFo0iDQUGihQApN9eJY4VcHFzZMZInF/UwE+9cGd85ZoB+ ejmREcGfCWuetQn4Nx8vzZ6dqyyLVNbWgXUxB/2wpL6sJZii7SKjXjrXo1Kt7uyVY32LNnpWSmM 0aJ8XDC7a4h5dMPHvf6O0r2wkR7OU/YuZDmAtzGEsb3VShPrMx5kN X-Google-Smtp-Source: AGHT+IEc6OGcAqqgNCFbLalQdcZ0MxHwOm2Ti3u21ccGWWv2ev5IfUyacdVqeUOHY1lyQSvrdbztJy9ncV0h/XrreYA= X-Received: by 2002:a17:906:3883:b0:a47:4a32:604 with SMTP id q3-20020a170906388300b00a474a320604mr1778023ejd.26.1711738274873; Fri, 29 Mar 2024 11:51:14 -0700 (PDT) MIME-Version: 1.0 References: <43539-1711733926.063834@011r.oEGd.QZp_> In-Reply-To: <43539-1711733926.063834@011r.oEGd.QZp_> From: Bart Schaefer Date: Fri, 29 Mar 2024 11:51:03 -0700 Message-ID: Subject: Re: "break" and functions To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52852 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: On Fri, Mar 29, 2024 at 10:38=E2=80=AFAM Oliver Kiddle wrote: > > 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. The latter was my expectation; I think the break is inside the loop. Skipping ahead: > It also rather surprises me that the break here even works: > > br() { break } > while : ; do > br > done % setopt localloops % br() { break } % repeat 3 br zsh: `break' active at end of function scope zsh: `break' active at end of function scope zsh: `break' active at end of function scope % unsetopt localloops % repeat 3 br % > 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. Right; since the break occurs in prefork() we're already deeper in the execXXX() call stack than anywhere the variable is checked. The function call re-enters that stack closer to the top, and finds the setting. > The anonymous function is > perhaps a two-stage process for defining and then running. Note: > while :; do; () { echo hello } > ${|REPLY=3Dx;break}; done > creates an empty file named x. Again, prefork() ... the redirections also occur before breaks is checked. Although this: echo xx > ${|REPLY=3Dx;exit} does bail out before completing the redirect, whereas this: echo xx > ${|REPLY=3Dx;return} does not. > When suggesting the test, the exact behaviour was not something I cared > strongly about provided it wasn't seg fault, infinite loop or similar. Yes, I understand. I considered testing this way for future-proofing: repeat 3 V=3D${|REPLY=3Dx; break} print $V I ended up deciding that it was reasonable to leave the "echo ${|...}" as an ad-hoc regression test in the event builtins do start "break"-ing. > 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. IIRC the entire glob loop finishes and then any (e) actions are applied to the resulting list. So "matched so far" is not well defined. I believe the only way to stop the internal loop "early" is the (Y) qualifier.