From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12254 invoked from network); 1 Nov 2022 19:09:46 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 1 Nov 2022 19:09:46 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667329786; b=RdbUDqV2KJKjUr7wHi+OBPBuz2JeStac6a08NPsDuKptqzoMcS1exgTbByq23pCjqkSRNHWxpY eRVDF/L8XLQmfKtrA6y56fV1i5S5tPcu33v8HZZf1xtr4VNlUq7rWJIKl4vbKP4Gu9hAHzH6tP HRqYJ+xSbPjjH7Afgf20DAMyGqD0XeAGVLu2IWnP4HKFcNsKnPwUjCBfP+9Gd9Z35scX17Esel mlRCxQmHtg3yfhL0cM4O8+5CQy075YfDX21oAkQwX8jogY9bch/yOCQ0bo+ahX5Dp3v+J1/iiy UMQt+l8MIXtmmuMpannbIaofzZk16L6ezxCHklzRzew0Zg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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=1667329786; bh=TkWkBLliWSIJkMz8Qcy3Swg8VwYAd0IpKco46/TF0J0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=g4vcSVFhPckq9jCPiQNdAKaCepArBezpP9VnPcTYV3qUGCzZJZjKMXxMKaynxvjllxDwd6wlJY L3agmXiQ7hz/xPKl61pWwYQ4uITxadb+gDxnaglSaRiyLeKOPYfwbMAK6Fs22Onb6ZIbGJfOpP jYSzZIpIVkMTpONTXFDytYULtPESRNUyo+G9Wzb8nCDFBtWZzBA7y166evCCntVQoFCg/f+qeG +FtJvT1qh/YxtV0b5BMS2hlUF7pAzTZW68Dm7x+CvjSR0Ytc0AsjMmHhsHMWk2FhF5yXScVXDF zxQVjF1tY17vWmro/XdtiR3Msz6h+3Rt5j13f89QHQFlTw==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=SIgfJaELuFpMkJY7rEbSVo6KYQ9SKvqGgjy3PlgVgD8=; b=eKsR97xgsxXP1YGFGMW5/hIrUt x6BeDMQjPzA9fKBnNeixnqobuPSKhUcLIwcP2gUOH6E5O7AXgrJge3tsKhZbnBvXFo1UG/nXdbwbS 9O/DWdrM6Hx9pQ75GVBN72KiXwEzsS2q99YPn+kAPCAVCXpxiw4of7g1xybWP1gd7ib3mT0KAmLdj TiYwYyJGcl0p6Owp8lAjZoycD0frT9XTBb+iDPxENloyZakYi7rSMetrM/H+yVnhHVpwsiA2xxeVq +rSzKKzqEaHSyWop9rabu/PZ+IXdbLly88bThzp+13aaxzpVTOF3pJS/0sAag+ItI8gLwUtFOG3+F aWKFKPLQ==; Received: by zero.zsh.org with local id 1opwds-000C5s-L5; Tue, 01 Nov 2022 19:09:44 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f46.google.com) smtp.remote-ip=209.85.208.46; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f46.google.com ([209.85.208.46]:35832) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1opwcq-000BQH-ID; Tue, 01 Nov 2022 19:08:41 +0000 Received: by mail-ed1-f46.google.com with SMTP id x2so23169825edd.2 for ; Tue, 01 Nov 2022 12:08:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SIgfJaELuFpMkJY7rEbSVo6KYQ9SKvqGgjy3PlgVgD8=; b=Ee96GlxtvILh8a+LS7mbaTL60+nq2Ewgl9eXKqzI3jfdVIFnSvkYGBy7A/acaeLeKr sElOF/wWake+c9NgMMf6eEjxUyboarjMOEkFdUrzJFC1zJqUmaXwVletpKlvgrx9wSnd cSDaHAE/Ru3AqRshgfiHucAQZ1QKhnPPozDAycmV9IfpNq7dSxHvUJMWQjwRtk524G3q eFthpkgub+Xq1xVUB2eBf5RU4Sjso6beI9eKYGugtJVtM+qFNhbjLJlvhSKcvDiUmrER aKC0VxVbE8o0TyjJnFoNxQ9geLB1YcqwveUsE7zH2vfhLjj5mFhpxIBo/izTaIzsYP6s oGfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=SIgfJaELuFpMkJY7rEbSVo6KYQ9SKvqGgjy3PlgVgD8=; b=l5Bnr3iMrXrMPvLwhOUw6Q4ENH5Mj4Z9D3VzlR2DfWDrV5puLa4rc3QpTUJTAN4D0E bz0uRDqoHhHHYPyrOKJZSZVI9dVuHbr6KtknQoMMtTRt0OpxsFWbPKC+SEVIhmW8uWkx 9mDXHdsYB/EZHkhvCfadX2Bmx2YjHVCpF0LBIOyVvGx7J73E1qoqAG/bDP+u79IwqneJ n9skaVuMR16a73d0p8WBQMEcHTcy5/6Vq3BHw88GNlvn907OreEHHpGXqmSyjSjClghQ 3zN4FSil8xzd/515zInrSVCSlqKT5x4XnoMkwdnXltrRBEN8jIjbCMaINvReTVRwLVrX 8kNA== X-Gm-Message-State: ACrzQf2K5HQ5v1dyy5YTmd3JPEWlYFnouUWuh1pQzPJi20lD+iFr8Dxa 67SmIKV+64ocCtU+sQMGPrVsMOZScs52Gx6q2Po14g== X-Google-Smtp-Source: AMsMyM4dlzqsiMJsT8PxyMpdUEubmhDHjc4C0B2xtg7G/NYAUA7j7F33rJWTI/2hnUOAZBmzZGrIq5AYM7iyhTXX8To= X-Received: by 2002:a05:6402:b0e:b0:461:f7a8:3e3a with SMTP id bm14-20020a0564020b0e00b00461f7a83e3amr20559626edb.372.1667329719819; Tue, 01 Nov 2022 12:08:39 -0700 (PDT) MIME-Version: 1.0 References: <5f18c162-e111-21ba-3ebe-ece09a477ecd@eastlink.ca> <552657de-31ce-255a-bc8d-7c9cd4b8eabd@eastlink.ca> <530b18d0-5e72-6afd-7448-cdff9c119bda@eastlink.ca> <9712ca3f-76f8-3aed-0a40-c6269afb73ad@eastlink.ca> In-Reply-To: <9712ca3f-76f8-3aed-0a40-c6269afb73ad@eastlink.ca> From: Bart Schaefer Date: Tue, 1 Nov 2022 12:08:28 -0700 Message-ID: Subject: Re: "typeset -p" inconsistency To: Ray Andrews Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 28311 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Nov 1, 2022 at 5:40 AM Ray Andrews wrote: > > On 2022-10-31 22:00, Bart Schaefer wrote: > > On Thu, Oct 20, 2022 at 7:25 PM, I wrote: > >>> typeset -T CDPATH cdpath=( ) > >>> typeset -aT CDPATH cdpath=( ) > >> The first one is the (incorrect) assignment for $CDPATH. > > Nobody called me out on that ... the first assignment is actually just > > fine. > > But the 'typeset - g -aT ... ' remains a bug as you said? Or at least a > redundancy? That's not what I said, in either case. Again, the -g appears only when, from inside a function, you ask typeset (by passing the -p option) to display a command that would create a variable that persists (is global, hence -g) after the function returns. The two examples above aren't really "redundant" either. You asked typeset to display commands to re-create all the current variables. The first command is meant to re-create the scalar CDPATH and the second is meant to re-create the array cdpath. Because they could have different attributes (the -U example you trimmed), it's not redundant to output each of them separately. The "buglet" is that if you execute both assignments, you end up assigning all the attributes of either one of the pair to both of the pair: % typeset -UT FOO foo=(a b c b a) % typeset -p foo typeset -aUT FOO foo=( a b c ) % typeset -p FOO typeset -UT FOO foo=( a b c ) Both have -U. Now add -u to just the array: % typeset -u foo % typeset -p FOO typeset -UT FOO foo=( a b c ) % typeset -p foo typeset -auUT FOO foo=( a b c ) The output is different for each, as it should be ... but if I execute that first one: % typeset -auUT FOO foo=( a b c ) % typeset -p FOO typeset -uUT FOO foo=( a b c ) Oops, we've added -u to FOO as well. This is an inevitable ambiguity in the syntax for creating tied variables. One way to resolve it may be to separate the declaration of tied-ness from the declaration of other attributes, as PWS mentioned, although I think there's still ambiguity with respect to in which order the declarations and the assignments must appear: % typeset -u FOO % typeset -T FOO foo=(a b c) % typeset -p FOO typeset -T FOO foo=( a b c ) Note -u has been lost from FOO by the subsequent -T declaration. This means we can't get away with outputting the assignments for each variable as we encounter it in the hash table scan, but I'm also not sure it's sufficient to first scan for and emit all the -T and then emit all the attribute settings. There's a comment in the code: * We choose to print the value for the array instead of the scalar * as scalars can't disambiguate between * typeset -T SCALAR array=() * and * typeset -T SCALAR array=('') This is an impossible situation for assignment whenever there are attributes of the scalar that are not in common with the array. One possibility (which would be a backwards-incompatible change) would be to treat typeset -a ... -T FOO foo as applying all flags to only the array, and typeset ... -T FOO foo (without -a) as applying all flags only to the scalar. That doesn't fix the assignment problem, though. Another possibility would be to allow attribute flags to appear between the scalar name and the array name, something like: typeset -T FOO foo but that breaks the use of our generic option parsing code and still doesn't solve the assignment ambiguity.