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,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3353 invoked from network); 2 Dec 2020 18:04:13 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Dec 2020 18:04:13 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1606932253; b=mdW8YCQv0tB7hWKWlS8FAE2dC+ugEPmuOyoP/9knwy3l0yOoKAObFNoH6d7VI1k0quoX+N3LBm LDZK9INm4tBLPWJFuG4EZzRRRNv4shc8fauY3u5SVO1j8UoX0RWgDTaQFzA9VQx3pAg+NIhIdB 3WkYLPjHKa6iW3hyV9IyQgHe48IWhZTZZTEwhJdntUZiEo177kQf60svKT33N4xZkFBkvPFbRD e67d8dM3bd0oS1sQ4s/nhWzyVytq0ZnJenfkPFELY6T85wbo7f81Tk+KHp2RpBUpYeSTZs7XCe 7OX/yPt+NmCmbxCXVDJV1RCmBsyHKZuDNE1N+8OyAwZ08w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f170.google.com) smtp.remote-ip=209.85.167.170; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 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-20200801; t=1606932253; bh=5/j5x1TyhhdTWPPNIO3tPi+B7yJRRk/pF4t8vwtSRlk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ZqnwIi9xwAoKZJyR0wR2exZXxGziDylBpAuIDPku/P0Hnf8sTMH7R43naButM3Zkf4UX4uR9o4 dMouBBE0MeuQRoBIjrEY6EuvYt0V4EyIge/0hmcOinin5PblWOD33B7rC5G36vRd5v8qAce4T6 8mD17ZbMrslTGshZmGDiv0hpiedpUoMyq/uT870nYsSSpppjWAT072rwhg7vZLOVued9LUrlFe pra1JXyKJPc3+fnyi/nJ91MzuXfDjA8lBQx/dc3xMhby5STba1xb3NsdXZynUDXHmPT41ucKXn 2aozq+f3jDJcqJqqqM42ZXILXS6KXNrlru+DVWpa8mrb9g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ShFr7wNHrvH/CUsB5da7RrYKxArm7zAXG8em+/dKsV4=; b=pQwgA2nhtRWdl9k4pawrro14oa y2wXWOCXdVRPwtCNpll8YEk6XizEWjxYQewGLclhCDl36ZvqS2k25rMfcbwt4alqRu7eHenDXyxAh gdOOBa4f1JSFzHxASmIYCl4n7nqBCOdnoSQHDn9L/LD/vMrwVrWIS/w6qvL6IsiycStEh3jRusGK1 EryvrU/tKabaPqCwHO1bGSts6mONC4QfUtkduqlqVJqGTWtB0yH+LwNg63Znazh90UR5pOOXU3PwD sIhwaGiqrptO6EgWybCFFigV1g7QX+pMMaha3rStoSMUzyD+Lpk5l4LwprA3wvi9YfKHl5wEO6dmG BJ9IVxNw==; Received: from authenticated user by zero.zsh.org with local id 1kkWU9-000Htr-2r; Wed, 02 Dec 2020 18:04:13 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f170.google.com) smtp.remote-ip=209.85.167.170; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f170.google.com ([209.85.167.170]:42521) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kkWTn-000HkI-77; Wed, 02 Dec 2020 18:03:52 +0000 Received: by mail-oi1-f170.google.com with SMTP id l200so2420987oig.9 for ; Wed, 02 Dec 2020 10:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=ShFr7wNHrvH/CUsB5da7RrYKxArm7zAXG8em+/dKsV4=; b=iU2pJ+EwgZPEQWWMpCH09YqkqTXzN0JbsfP/WANwBLOvlCmYng6tzjnV+GhNFBAPQ6 IDf9bR5WNo++AT8tEFavYX4lihZJp+qe6oP1PkXOWwtcMz2e3TIJWgc6CCJgyJ6AAAgf P0cbIErp9dA63Qr4zHNupBosE3k1B0pUoCrbmE/tTkAiFRSrDYqmoua/W0Ju7X37o2kh xKhjvs1iaPHUjQBLgEmq+yj9s5kakmzT0ppj0VeGmbAbCjtq3qq5PUyMg4ywftE5EctO YacVe/Lu82qW+Vv4Zuru53cse24I2LD8u4MYnvL5qorcxwT25EwzfaUOUvnalKv3Eqwh 0KOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=ShFr7wNHrvH/CUsB5da7RrYKxArm7zAXG8em+/dKsV4=; b=U81oDvFpofjzm9E/z0/P/MZ/cVZBVL0QBRwBFtdPZQC06ukZM9Bt1vNZoItevLAZYL /+6nq0S3l/xfB6a5YCoyxjSsFBONEVvCocQL4x12WjG9tADAaiplqjaXx0pnWrAewhBz Sjx5vRI1l57KRfssgpGJUQlJ+SEUSYnB4yxV+ZS8BkjnMkOtUvrDbo+M4ciGgRu6HRxy rq0w21yPq6H4MI87vuH7Kj+6nUQZrxdfH9wcBKU3NlrqBu9jBFAuUq5j51m/H3hhCtBY RnNWNOvOVDYa7UXDDVP5iwm8MQuHiUee2UaCxL45BOdtU3wbOkJKkvhO6V3B8oKXBlrm YjeQ== X-Gm-Message-State: AOAM530rj3Xe6uzcOvsn4unA2bVU3DF2v7vVZiAwO51RMalFGZSfeQT2 ItxFIhLacUbn74t64b52NIcHU8qW8GuXJ2T3JQWGSfHm52Y= X-Google-Smtp-Source: ABdhPJyjJ1Df1iYvVaulstlr/MF1EwZZVoWnUO7jqLbE3yz0JxInUxkjPLfNqNQ34ZkCXwWNrVAUKzMSgFVkPwd8pP4= X-Received: by 2002:aca:6087:: with SMTP id u129mr2624277oib.173.1606932229456; Wed, 02 Dec 2020 10:03:49 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Wed, 2 Dec 2020 10:03:38 -0800 Message-ID: Subject: Re: One possible answer to typeset vs. unset To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 47713 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: Archived-At: On Wed, Dec 2, 2020, 9:19 AM Vincent Lefevre wrote: > > On 2020-11-28 11:49:12 -0800, Bart Schaefer wrote: > > The typeset -AEFHLRTZailux options are applied upon the first > > assignment to the variable. > > Could you explain the following behavior? > > zira% ./zsh -c 'typeset -E x; echo $x; echo $((x+3)); unset x; echo $((x+3));' > > 3. > 3 > zira% > > Why do I get "3." if the -E option isn't supposed to be applied yet? The short answer would be "because math context is magic." The longer answer is that $((x)) is not the same as ${x} or $(($x)), and the quoted sentence is more a description of behavior than of implementation. What the branch attempts to do is create a "null" concept by combining two flags, a new one PM_DECLARED (actually an overload of one that is used only at shell startup) plus PM_UNSET. When a variable is assigned, both are cleared. When a variable is unset, PM_DECLARED is cleared and PM_UNSET is asserted if necessary. When a variable is dereferenced in the normal ${x} way, PM_UNSET results in empty string being returned no matter what the declared type is. With the exception of adding PM_DECLARED, this is the way that locally scoped variables already work. Math context doesn't care about PM_UNSET in the same way; it grabs the value from the union in the parameter struct, which I deliberately left unchanged as a zero-value double. This is one reason "null" is represented in the PM_ flags rather than in the union itself. So $((x)) comes back 0.0 instead of empty string, and $((x+3)) works like it always did.