From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: Bug with unset variables
Date: Fri, 13 Nov 2020 09:51:58 +0100 [thread overview]
Message-ID: <CAN=4vMpdmZti7oAykW_=NW_9aVA2sVMkVd-A=t5oJyCcua4S5A@mail.gmail.com> (raw)
In-Reply-To: <CAMP44s0bsQ0iZk4652GC2-tOx9OA8PNCtcraGvjkFyzY234uog@mail.gmail.com>
On Thu, Nov 12, 2020 at 10:08 PM Felipe Contreras
<felipe.contreras@gmail.com> wrote:
>
> On Thu, Nov 12, 2020 at 1:11 PM Roman Perepelitsa
> <roman.perepelitsa@gmail.com> wrote:
>>
> > 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:
I didn't realize you cannot unset variables in JavaScript. Then
comparing it with shells isn't very useful.
> "unset foo" and "foo = undefined" do *exactly* the same thing
`undefined` is just a value, so `foo = undefined` simply changes the
value of foo. You can still pass foo around, just like you could do it
if it held any other value. Unsetting a parameter in a shell is quite
different. It's impossible to detect a difference between these two
cases: 1) foo was never declared, and 2) foo was declared and
subsequently unset. (At least in global scope. Shells differ w.r.t.
local variables.)
We'll need another language that allows unsetting variables to have a
meaningful comparison. How about elisp? As I mentioned earlier, it
shares two important properties with ksh/bash/zsh -- dynamic typing
and dynamic scope. In elisp declaring a variable and then unsetting it
is not equivalent to just declaring a variable. Like in zsh and unlike
ksh/bash.
> In JavaScript "var foo" does not set foo to an empty string.
It sets *some* value, specifically `undefined`. In shells there is no
such value, so assigning `undefined` is not an option. The only
options are: assign the default value that corresponds to the
parameter's storage type (an empty string for string parameters) or
leave the parameter unset. The latter has no equivalence in JavaScript
because JavaScript has no notion of unset variables.
I don't think this discussion will affect anything of substance. I'm
continuing merely out of politeness. You've asked why I consider the
behavior of zsh natural and I'm doing my best to explain. I can see
that you consider the behavior of ksh/bash natural and I agree that
your position is consistent. I'm not arguing that what zsh does is
objectively *more* natural, only that it's also consistent and has
precedence in other languages (elisp).
I think I've found a language that has constructs equivalent to
typeset and unset with the same semantics as in ksh/bash. In Lua this
snippet:
local x
x = nil
Is equivalent to this:
local x
Moreover, variables to which nil has been assigned are
indistinguishable from variables that have never been declared.
"Variable foo is nil" has the same meaning as "variable foo does not
exist". Like in shells and unlike JavaScript.
Roman.
next prev parent reply other threads:[~2020-11-13 8:52 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
2020-11-13 8:51 ` Roman Perepelitsa [this message]
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='CAN=4vMpdmZti7oAykW_=NW_9aVA2sVMkVd-A=t5oJyCcua4S5A@mail.gmail.com' \
--to=roman.perepelitsa@gmail.com \
--cc=felipe.contreras@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).