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

Re: Bug with unset variables



On Thu, Nov 12, 2020 at 1:26 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Thu, Nov 12, 2020 at 10:47 AM Felipe Contreras
> <felipe.contreras@xxxxxxxxx> wrote:
> >
> > No. Zsh is not consistent. I did not type /typeset var=''/, I typed
> > /typeset var/.

> So now we have to decide what to do when with local variables.

Which is probably the main purpose of typeset (i.e. local).

> They
> can either have a totally new semantic, or we can follow the semantic
> for globals.

Syntax is not semantics.

  var=
  typeset var=

These two have a very similar syntax, so it makes sense that the
semantics are the same. But there's no previous equivalent of "typeset
var".

> Guess which one makes more sense when you are adding
> local scope to a language which previously had only two possible
> conceptions of variables (exist and are empty, or do not exist at
> all).

There's a third conception; a non-empty value.

  var=
  typeset var=

  var="foo"
  typeset var="foo"

These are obvious. The only thing that is left is deciding what
"typeset var" does. These are the options:

1. Errors
2. Nothing
3. Changes the scope
4. Changes the scope and sets an empty value
5. Changes the scope and sets an arbitrary value

Obviously 1 and 2 are not useful options. 5 doesn't really make sense,
and 4 is a subset of 5. More importantly; there's already ways to do 4
and 5.

So why not do a) something useful, b) something that isn't arbitrary,
and c) something that can't be done in other ways?

> That said ...
>
> > Adding a setopt option for the new behavior doesn't break a lot of
> > existing zsh code.
>
> It probably wouldn't break any _scripts_ even to modify the behavior
> of KSH_TYPESET for this.  Whether we can cleanly perform an implicit
> unset in the C code structure, and (if not) whether cobbling this in
> is worthwhile, I haven't investigated or formed an opinion.

I have already started some experiments.

At first glance there doesn't seem to be any straight-forward way of
doing this, but I'm not familiar with the code either, so it would
take a while for me to reach any conclusion.

Either way it seems clear to me reorganizing the code to make it at
least possible will remove many of the weird checks and corner cases
scattered all over, or at least make them more understandable.

We'll have to see.

Cheers.

-- 
Felipe Contreras




Messages sorted by: Reverse Date, Date, Thread, Author