zsh-workers
 help / color / mirror / code / Atom feed
* More rabbit-holes with unset variables
@ 2020-11-25  7:02 Bart Schaefer
  2020-11-25 13:19 ` Stephane Chazelas
  0 siblings, 1 reply; 40+ messages in thread
From: Bart Schaefer @ 2020-11-25  7:02 UTC (permalink / raw)
  To: Zsh hackers list

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.


^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2020-12-01  8:50 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  7:02 More rabbit-holes with unset variables Bart Schaefer
2020-11-25 13:19 ` Stephane Chazelas
2020-11-25 22:17   ` Felipe Contreras
2020-11-26  6:10     ` Stephane Chazelas
2020-11-26  7:20       ` Felipe Contreras
2020-11-26 11:21         ` Oliver Kiddle
2020-11-26 11:29           ` Roman Perepelitsa
2020-11-26 19:08             ` Felipe Contreras
2020-11-26 19:29           ` Felipe Contreras
2020-11-26 21:13           ` Bart Schaefer
2020-11-26 21:31             ` Felipe Contreras
2020-11-26 23:29               ` Bart Schaefer
2020-11-26 23:32                 ` Bart Schaefer
2020-11-26 23:53                 ` Felipe Contreras
2020-11-27  0:23                   ` Bart Schaefer
2020-11-27  1:51                     ` Felipe Contreras
2020-11-27 20:01                       ` Bart Schaefer
2020-11-27 21:49                         ` Felipe Contreras
2020-11-27 22:06                           ` Bart Schaefer
2020-11-27 23:35                             ` Felipe Contreras
2020-11-26 22:07       ` Bart Schaefer
2020-11-26 20:41     ` Bart Schaefer
2020-11-26 20:49       ` Stephane Chazelas
2020-11-26 21:20       ` Felipe Contreras
2020-11-26 22:41         ` Bart Schaefer
2020-11-26 23:45           ` Felipe Contreras
2020-11-27  0:09             ` Bart Schaefer
2020-11-27  0:30               ` Felipe Contreras
2020-11-27  0:51                 ` Bart Schaefer
2020-11-27  1:30                   ` Felipe Contreras
2020-11-27 20:54                     ` Bart Schaefer
2020-11-27 22:10                       ` Felipe Contreras
2020-11-27 22:39                         ` Bart Schaefer
2020-11-28  0:00                           ` Felipe Contreras
2020-11-28  0:04                             ` Bart Schaefer
2020-11-28 10:52                               ` Felipe Contreras
2020-11-28  0:36                             ` The emulation rabbit-hole RE typeset/unset Bart Schaefer
2020-11-28 11:35                               ` Felipe Contreras
2020-11-28 16:56                                 ` Bart Schaefer
2020-12-01  8:49                                   ` Felipe Contreras

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).