Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
More rabbit-holes with unset variables
- X-seq: zsh-workers 47622
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: More rabbit-holes with unset variables
- Date: Tue, 24 Nov 2020 23:02:05 -0800
- Archived-at: <https://zsh.org/workers/47622>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-11/CAH%2Bw%3D7Zag5MG5D%3DcRS2UMSsqJ0t%3Diw5MH9j8%3DHBO1Q77nbs03w%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-ot1-f50.google.com) smtp.remote-ip=209.85.210.50; 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:from:date:message-id:subject:to; bh=p93o2msBCT00RoTNmQPHsQsdq0yzqEzOw74C54hvQeI=; b=iCHk3fA36SUFiQj9JKOt0gJW37j0ey3lAjZwwNx0qeegCq8IvZ2r39dIALWyXnzAFk Zd+z9zU5YjvB+7VPC2NWzPWyhcN2MvS05GyPKUPQ7waS1H0GRUkzzcqDpi7ocuoeV0pH Npx8bgThOst2yabTU8lmFaoRYIpDd9lrRvf+2HiblV2AdG4ijn/tuKal4ADj2g/aom1Z Yx0TeAkNQIi63cm6S+2OGcibjNw8emZ13fDHLORJ1HBRR5toOeGs0f6NAtmARqFSDA/t txWZQf4kxnoNvvOkQpDehYnV63pr/OqozaDlV5zuOX1P1VAvpS0Wt2c1qmPxu60TQeWO kACg==
- 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>
- Sender: zsh-workers-request@xxxxxxx
I was experimenting with ksh to look deeper into adding behavior to
ksh_typeset in zsh, and discovered that this example:
function ff {
echo start
typeset -i i
typeset -p i
echo ${i-nil}
unset i
typeset -p i
echo end
}
Outputs in ksh93:
start
typeset -i i
nil
end
And bash:
start
declare -i i
nil
declare -- i
end
Although both of them have a way to represent "declared but not set",
neither of them treats "explicitly unset" as equivalent to that, and
neither of them preserves any type information across unset. Only
bash regurgitates the "declare" after unset, but that's an effect of
the implementation of -p rather than of the state of the variable,
because function scope still applies to $a in both cases.
(I had to remind myself that "ff() { ... }" in ksh is NOT a "function"
in the sense of scope locality.)
Therefore, this isn't as simple as having zsh create an unset variable
when typeset is given no assignment, because subsequent assignment has
to preserve the type of the variable, which normally does not apply
after unset.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author