zsh-workers
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Bug with unset variables
Date: Thu, 12 Nov 2020 15:08:13 -0600	[thread overview]
Message-ID: <CAMP44s0bsQ0iZk4652GC2-tOx9OA8PNCtcraGvjkFyzY234uog@mail.gmail.com> (raw)
In-Reply-To: <CAN=4vMoPrb3EVmM7T57DpPvWYdndHdiwhqpi-V+5JgGVbdh8qQ@mail.gmail.com>

On Thu, Nov 12, 2020 at 1:11 PM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> On Thu, Nov 12, 2020 at 7:47 PM Felipe Contreras
> <felipe.contreras@gmail.com> wrote:
> >
> > This is distinction without a difference, like saying we are not lost,
> > we just don't know where we are. Conceptually it is the same thing,
> > you are just using a different word for it. It's wordplay.
> >
> > An unset variable is for all intents and purposes a variable with a null value.
>
> Only in languages where variables cannot have null values, and only
> because you can declare "null" to be a synonym for "unset" in this
> case.

No. Intents and purposes don't depend on the language you cherry-pick.

> > JavaScript
>
> In JavaScript you unset a variable with `delete foo` and you assign it
> a "null" value (in quotes because javascript has another null) with
> `foo = undefined`. These are not equivalent.
>
> Note that these two snippets have different effect:
>
>   var foo
>
> and
>
>   var foo
>   delete foo
>
> Just line in zsh, and unlike ksh/bash.

No. That code doesn't even work in JavaScript:

  > var foo
  undefined
  > delete foo
  false

Delete foo returns false because it didn't do anything.

  > var foo="test"
  undefined
  > delete foo
  false
  > foo
  'test'

The variable is still there with type and value.

If you turn on the strict mode you get: "SyntaxError: Delete of an
unqualified identifier in strict mode."

The delete operator is there to handle properties of objects, not
variables [1]. The closest to unset is assigning a value of
"undefined".

But the important thing is that foo is *never* an empty string.

> > Python
>
> Same thing but `del var` and `var = None`.
>
> Et cetera. ksh and bash are rather exceptional in this regard.

This is a false equivalence. You are talking about two different
concepts as if they were the same thing. They are not.

  foo="global"

  func () {
    typeset foo
    unset foo
    foo="local"
    echo $foo
  }

  func
  echo $foo

In this example unset does not do the same thing as the del statement
in Python. The scope of "foo" is not changed. The equivalent of "unset
foo" is "foo = None".

A real equivalence is undefined in JavaScript:

  var foo="global";

  function func() {
    var foo;
    foo = undefined;
    foo = "local";
    console.log(foo);
  }

  func();
  console.log(foo);

In both cases "unset foo" and "foo = undefined" do *exactly* the same
thing, which is return the variable to its original state.

And in both cases if you remove "typeset foo" or "var foo" the effect
is *exactly* the same; modifying foo inside the function modifies the
global variable.

If you compare apples to apples the equivalence is obvious.

In JavaScript "var foo" does not set foo to an empty string.

Cheers.

[1] http://ecma-international.org/ecma-262/11.0/#sec-delete-operator

-- 
Felipe Contreras


  reply	other threads:[~2020-11-12 21:08 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11 15:57 Felipe Contreras
2020-11-11 16:13 ` Roman Perepelitsa
2020-11-11 16:56   ` Felipe Contreras
2020-11-11 17:02     ` Roman Perepelitsa
2020-11-11 18:03       ` Felipe Contreras
2020-11-11 18:16         ` Roman Perepelitsa
2020-11-11 20:42           ` Felipe Contreras
2020-11-12  0:20             ` Mikael Magnusson
2020-11-12  1:10               ` Felipe Contreras
2020-11-12  8:45             ` Roman Perepelitsa
2020-11-12 10:47               ` Peter Stephenson
2020-11-12 18:48                 ` Bart Schaefer
2020-11-12 19:49                 ` Felipe Contreras
2020-11-12 18:46               ` Felipe Contreras
2020-11-12 19:10                 ` Roman Perepelitsa
2020-11-12 21:08                   ` Felipe Contreras [this message]
2020-11-13  8:51                     ` Roman Perepelitsa
2020-11-14  0:52                       ` Felipe Contreras
2020-11-14  5:41                         ` Roman Perepelitsa
2020-11-16 19:41                           ` Felipe Contreras
2020-11-16 20:22                             ` Roman Perepelitsa
2020-11-17 20:28                               ` Felipe Contreras
2020-11-18 22:45                                 ` Daniel Shahaf
2020-11-22  1:20                                   ` Felipe Contreras
2020-11-23  4:00                                     ` Daniel Shahaf
2020-11-23  6:18                                       ` Felipe Contreras
2020-11-19  2:59                                 ` Bart Schaefer
2020-11-22  1:50                                   ` Felipe Contreras
2020-11-17 20:54                             ` Bart Schaefer
2020-11-22  1:49                               ` Felipe Contreras
2020-11-23  6:48                                 ` Bart Schaefer
2020-11-23  7:26                                   ` Felipe Contreras
2020-11-23 20:26                                     ` Bart Schaefer
2020-11-23 23:39                                       ` Felipe Contreras
2020-11-24  0:52                                         ` Bart Schaefer
2020-11-25  8:46                                           ` Felipe Contreras
2020-11-27 15:44                                             ` Daniel Shahaf
2020-11-27 20:49                                               ` Felipe Contreras
2020-11-27 20:59                                                 ` Daniel Shahaf
2020-11-27 21:33                                                   ` Bart Schaefer
2020-11-27 23:37                                                     ` Daniel Shahaf
2020-11-27 23:45                                                       ` Bart Schaefer
2020-11-28  0:24                                                       ` Bart Schaefer
2020-11-28  7:32                                                         ` Bart Schaefer
2020-11-28 12:05                                                         ` Felipe Contreras
2020-11-12 19:26                 ` Bart Schaefer
2020-11-12 21:48                   ` Felipe Contreras
2020-11-13 22:17                     ` Bart Schaefer
2020-11-14  0:58                       ` Felipe Contreras
2020-11-11 18:36         ` Bart Schaefer
2020-11-11 21:08           ` Felipe Contreras
2020-11-11 17:02     ` Peter Stephenson
2020-11-11 18:05       ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMP44s0bsQ0iZk4652GC2-tOx9OA8PNCtcraGvjkFyzY234uog@mail.gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=roman.perepelitsa@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).