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=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, T_SCC_BODY_TEXT_LINE 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 4ABF22680D for ; Thu, 7 Mar 2024 05:54:02 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709787242; b=eDr/g0Y8WwDpjH9q7p1HPjw30EQNFnVCmp/i2I1CdiDAnaNZqo6Yy+12kqyl74PG69G7AQh3ow iiB19UGzpWV0O631dC2XEbkl/qulP9z60ZGrBW9zFKrJcADDJWFyC1hEB9l4Ugeyd22Qs2b17X aJi/YDFrBnMqwIF9ROrzA1sQ7SNZosRAXc47Hzs2N4qSe9g3VTcVfOL/LF/bhPJqlAc5QVdN7Z jaCubx33XLHE0Lqem0ZfA1IlhB+lqbvMiAJyC0mZXRRHSDb+sXewIrvR6/uCwKJWSfyYIapRy1 u+QMenEejQpOBDbS2Hcg4axI7BaezJey/VvJbGjPCUGsfA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f46.google.com) smtp.remote-ip=209.85.218.46; 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=1709787242; bh=gOK3j60ufXWPu923bjuh56n3db8qBpCaIJ8QYbZL/2g=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=ipwwic59Y0Le5S2f0iqRG14rd6zuptUAwWTwwIBsUD2MeDFzhFjJ+K5M/q8BXE9X2Km1lnYMRj Iqaqf5TxSH14zh//jIzSZLmlidF8dZyeD/Ca8mIvBwtO6JzKMf9nqmFJVyE2MXsvEdtJHitqza dxvR7J4sUvo1I1O3V1vmYSe99oseMSh0RxzTe0Nsxb6vTInNZgEXP1PdvTbtOY+SToh8kuZQk6 fSssD+rYrkhK+kXsREXsDPMx5f8msRvfA409l9yWsos4cBLMSsHyKt+yEli3h/SUmCW9dgSOww dv37Z2I5uVEJgU2Ewo1Qrokg+n5QDyLNwRNn/nrAXBZpVw==; 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:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ZW6ldre+5celgHbwoQfuciOFyWSwwX8NMuzQrHwIf2A=; b=D6HDrnMU1KfOMXIMNqduIO2egl ySLqGkkTk7M5O5p+WDDT03GV0zZLy8RzrSexO+Qmesw+1WYbCXPbdrIRkkE+6+FLPjbf1j2sg3fhY dKNFJTxPwz2SfrTLEV/4XaYzkKqwqWVUti4VVPyhFhI2ea97cFFmbW8wF8t+R091AuKUwZj1u1F6d i3EOPAIma5OS19+XM8BEGt1B5jfdep8J7RJZEx5daxqyyQdEf1mqQYzpajyM/qyOJWDmX3bubJPKj ctZ9Ov8ooUo/ZUw3TIcrPxtUjeNoT0Ku/w0L1XBbfEV/aWAy3gXp3Q9b43VE6vAFkZst8g0UrQI7+ IICIcDgQ==; Received: by zero.zsh.org with local id 1ri5lY-000Lpf-LH; Thu, 07 Mar 2024 04:54:00 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f46.google.com) smtp.remote-ip=209.85.218.46; 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-ej1-f46.google.com ([209.85.218.46]:46463) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ri5lE-000LWU-Tr; Thu, 07 Mar 2024 04:53:41 +0000 Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a449c5411e1so58774766b.1 for ; Wed, 06 Mar 2024 20:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1709787220; x=1710392020; darn=zsh.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ZW6ldre+5celgHbwoQfuciOFyWSwwX8NMuzQrHwIf2A=; b=PjOsF561A1c+CbyOvKFqOo27iuTcPf38x6zzFWoNqsKL4qaZ2HZA+LjfkIc0hQpGmc d/zokR7BxYhxUAhfXJLvgvFA1t7wRyWY0yvsJgOa5pJYbkTkAT+e0odsHaVccpvIFEVx Tj+KIWIPOVG6mSHkzMxWgX471WZrfcWwe5BJSPnfTuPe7SrYf7bc+24Evsy2RsplcvQi DLFpzYQNatnEII3f0CguEyX37uqVghUAB7HX/Rv5NH6b0pQnE+OfLJMqUzqm8syBhhaP uVrREKYgWWi93MGfY3I4UerVmZsQQuZ1A6+gP8hKrWQfnKAjCOOyvSGaf14DdW57uGuW l+Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709787220; x=1710392020; h=content-transfer-encoding:cc: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=ZW6ldre+5celgHbwoQfuciOFyWSwwX8NMuzQrHwIf2A=; b=i4SaTcAGU3jnGn+mVP5JHjP0tTy9k7BYig+8VTOZkp+41O8HnV+XHEmncwqfKswUNJ iDEKgQZR1DAOChV9t8FxxbhbAADFTXsA1cAsOxm1JeVIgUeK5sQeiYsMdwF6hOf5pLmY 7yiZRpm6pHEP+tN6m5IHve2oCM5qY+DDc98JCbRZJdoXXUni4ln5xgjixMmGSvf08wJQ R128Herh7i2FqPd9FlCK+2XcUjBqa2mXhDVcPPUiUQy2Lgne5yYukPMHPMp6daN+Lin7 c0flZnWR/jFTiTcqm7wAeoACZrMYzdLLDtnz6v/PhgtkvxT/C87MhGPt4Jo5NGAYicgh nQqA== X-Gm-Message-State: AOJu0YyYg8xcAJizaWeYuLRx8AEITGJBnP00jnzJsbyitvNrtUusBoir GBZPGf58ftgIFrQHtPFxeTsts/FpyEFAWNAAWlSHOaiPWi+RLQ2ynBNwIE+qB77IOMvm8Q1xUTC tpKf9jxYP6z+7ozswpWYROtSkvN8F+J1wuJFq X-Google-Smtp-Source: AGHT+IFOe6NFBnvj9zpz++RPrgpG+l7XUnwQmyNvyCcy8JTsxbLpSvDRuGRLTuyPMUf0sTPvyuQza99jzncUSPznreM= X-Received: by 2002:a17:906:4156:b0:a44:7ad0:8069 with SMTP id l22-20020a170906415600b00a447ad08069mr11238957ejk.72.1709787219987; Wed, 06 Mar 2024 20:53:39 -0800 (PST) MIME-Version: 1.0 References: <20240305065606.ccr2ieheahslcpye@chazelas.org> <20240306175711.t3uz2sery3b6tbjw@chazelas.org> In-Reply-To: From: Bart Schaefer Date: Wed, 6 Mar 2024 20:53:28 -0800 Message-ID: Subject: Re: [PATCH?] Nofork and removing newlines To: Mikael Magnusson Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 52701 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 Wed, Mar 6, 2024 at 2:22=E2=80=AFPM Mikael Magnusson = wrote: > > 1) $(foo) will optimize away an extra fork if foo is an external command > 2) ${ foo } will fork the same amount of times as 1) if foo is > external and not at all if foo is a function. You're almost quoting the FAQ entry. :-) > "${ foo}" and ${ foo} having the same wordsplitting behavior but only > differing in stripping newlines feels a bit magical and weird. One question (and sort of the point) is whether anyone would really notice. If you put it in quotes you're expecting a literal result, and if you (for example) assign it unquoted to a scalar you're expecting it to "just work" the way assigning $(foo) would. It's a bit unusual but it seems to preserve the principle of least surprise, and it uses the least amount of extra syntax. On the other hand I'm not highly invested in this. In the absence of this (no)quoting behavior, I've found I nearly always want ${=3D${ foo }} or ${(f)${ foo }}, each of which gives exactly the same result with or without trimming. > We could in theory add some new () flag, T for trim is free eg, > ${(T)${ foo}} is somewhat more ergonomic than ${${ foo}%$'\n'} I admittedly (still pre-patch) have used (f) for this when I know there's only one line of output. I'm just struggling to think of where else I would use a (T). Returning to this other bit ... On Wed, Mar 6, 2024 at 2:42=E2=80=AFPM Bart Schaefer wrote: > > On Wed, Mar 6, 2024 at 2:22=E2=80=AFPM Mikael Magnusson wrote: > > > > Is there some strong reason we could not allow ${(T) foo} btw? > > "{ " (curly bracket followed by space) is recognized like a syntax > token. Code-wise, a sequence starting with ${ (with or without the space) and ending with } is lexed into a single STRING token. (If it's inside double quotes, the entire double-quoted thing is a STRING token, but you can have nested quotes inside the dollar-brace inside the double quotes, etc., so this has to work recursively, and so on.) So the lexer has to decide when it sees dollar-brace how to find the closing brace. Skipping over parameter flags before deciding to switch to parsing something that looks like a function body might be possible, but doesn't really fit into the structure of the lexer. Deciding based on the very next character (space or pipe for a command, or any other for a parameter) makes it tractable. The lexical problem aside, when you get to the point of performing the substitution, even if the command interpretation were deferred until after all the flags are collected, it would still have to function much like ${(flags)"$(cmdsubst)"} would, so it's a lot easier if it's already structured as a nested substitution.