Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: One possible answer to typeset vs. unset
- X-seq: zsh-workers 47713
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: One possible answer to typeset vs. unset
- Date: Wed, 2 Dec 2020 10:03:38 -0800
- Archived-at: <https://zsh.org/workers/47713>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-12/CAH%2Bw%3D7ZNw_-_P24m%3DMO16Jxj9u%2BBpwQAzzJ_71pOpRJiPUdMYg%40mail.gmail.com>
- 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
- 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==
- In-reply-to: <X8fMgx5uY0atuMZK@zira.vinc17.org>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <CAH+w=7Zh8URUiLF2n1x-ZrvKO+=JC8wf+n692sRsFTRbkJrzXw@mail.gmail.com> <X8fMgx5uY0atuMZK@zira.vinc17.org>
- Sender: zsh-workers-request@xxxxxxx
On Wed, Dec 2, 2020, 9:19 AM Vincent Lefevre <vincent@xxxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author