Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

More rabbit-holes with unset variables



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