From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19923 invoked from network); 14 Nov 2020 00:52:38 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 14 Nov 2020 00:52:38 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605315158; b=sh2sYc1EOT4xrUeHet5KVUwbMQ7YjAmt6Q6Xxh59Kiwd1++WsnzID3g9rv9rqXe8UF1yHoVRoQ rSnEjmRtIQ3RA4hjAsl/Zdh8zd8PYT89sxu8bBNI8Y+t6fqyC69gxFhnZo61le9d0CDjsn296R 7M1V9jL7VZNqxYpNWjFJlR6AdM0OXNHcgnopY1dYUOGwRzXMuEseFj9VU7hoIZWGSWq2LxEIB9 P8zwaWeYBjK2sUTeAID6f9Db/ORDdC4VCb7rect78keGwT23XT3dgO3pFio/2Cf4blqrKFb7aQ n8kAYye6XeCk1WFJnTZuocZhxrkVx+aTUFJXs5egm1BoSQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f53.google.com) smtp.remote-ip=209.85.221.53; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1605315158; bh=430seq0edXGDbkdnbNosB3YAeY+TRoZWYsC/Q37tO4k=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=FddOXu/suPmWsgDE6qtWPvfAE3QguHMOp5WCNUAEaX/ffqsuj919HUkSYUzcYACdVYX51APo17 8aaHUQbRAdpk/wUYs6UvhmaVcTjXXuSQ5cI+ma3R+J3G93MrEaqMdqrNo4TeiBTrlqXPV4W3Lp 9BirAJ3RGGrzxMM7x59TfJWcgnOwfmoV2g3bkgAYn85jrYfkyqFCfBnd5pEOC/EuDdhhlQE2ql nB3vouJ/WqAC4WwAnP+Z2Ve+Y1BGKRexMZK4Gd7JnfUleYt2SUzlwJ92zRVotfpONZIf644wPH XjghgPrWCJ726ZgLMIiRiXG2lkyWqiKeLFypeaaZ4MuxbA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=3bLANWb6ntxhR82lELgPNBsnWpVecIUzw9/ZoY9Kj8k=; b=GWdn3UCXh82uNJBzyV9t5B4miV 6yvwul4ZorQE2JLmgbrrW8WHaljCOXSkRMjXyJjGXBp53Y6Yzv1qNvg4ydWQqqG3w3+TEhBlptDzr 54mi2bDGEdTbgyh+v4ugJMBn+TKJK03t9CrMS2OKlW9dSQRnBmV6OL2pjrnrXrhUlKf2zLke3x0d8 DmBlwjfEgddgntpnuO1ce1AqViyk2zKz9mrF+85ba0/8T+rqFsqnEyTpSoQcL3MpDDMEXYkPO+Ipq HiOX+YOi3jypFby0fVQ8NZMoxipPnDbOmWpkWAfZlJXgpSkvYUy2+g2m7sRAo3AD9EshF0s+RiOoF 44WrglRg==; Received: from authenticated user by zero.zsh.org with local id 1kdjns-000B3B-UN; Sat, 14 Nov 2020 00:52:33 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f53.google.com) smtp.remote-ip=209.85.221.53; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wr1-f53.google.com ([209.85.221.53]:39228) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kdjnf-000Av3-LM; Sat, 14 Nov 2020 00:52:20 +0000 Received: by mail-wr1-f53.google.com with SMTP id o15so12159849wru.6 for ; Fri, 13 Nov 2020 16:52:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3bLANWb6ntxhR82lELgPNBsnWpVecIUzw9/ZoY9Kj8k=; b=XiHyQseAR7DwDMrhjvZ07FIJPezqeqh8Xa9YBBzuvNOKuMFh8pHHpZEX478VAcvAGy ss+fqFsKn0k2Un6jDtFUuzUZVs/Nq7iaG4CHEBv/dfC1zO1kqZipjtqC5lqAjkevpNNC g+Zu55Twz2nng3kHNIjIRzaDEJD5fLr3np8zlgSArCgbTwQl2nP5ZvfxCD+xefl1rQGi QbLk24zextVGJXdZsamS8+BLDxf8FYhtNaiLLy8nklArBNfou3qmpklIcu1z3Jqf4zwn eiaZJJPY5a/prbqeQQOFu3Vzr7psGTZAB+ofBAxyMTeYmaYNY9p/F0UtRXuBbBvb0zCf W1ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3bLANWb6ntxhR82lELgPNBsnWpVecIUzw9/ZoY9Kj8k=; b=CLeaNHp0bxP2RkfwYT53/tqkf/b0RpAUcflq8rdoExnRWKWgcELDfBNCYdJK2tIkXE YlEf9tlknI73i8NSB0Kf+brd9rt2B19gsBP4pwQ8zFxWI4Md4hYgvpXC9oiRmiibuy6S ZpbnGnBcVoW6aIA+VapM/SL7kyn+00T8jKyF2doAEaLD0kwaFU4bsdSl0xvfIsiVt2ye HT1efgLOVpk9TkDznVlr5wAbFFnedsqufOd+NY8Y9W6lGEDRH/Ay3T1w0n/zy3PhXEQ3 5Hp8Ue9tU8qBogw66DDatCxSiA+2QOdMe5/YlKeXQY+YiQ6Ru+S+ZT7Hw33+70zIwBo3 8GMQ== X-Gm-Message-State: AOAM531a2u7kj6VUWRgcdm5okg+KXP7pWCVauXwD9g5qSU/x8Y4TORgz m/qytkh+sWdpMBEnx4jKlHwSBMVEXtcMvbFP4RQ= X-Google-Smtp-Source: ABdhPJxIbmGgyT6N04u4ZFgKXN8JLsPO1B2CMBWS+I1UU+h2dmgN+TfMXzk4U6r5SYsloKlkbNt5dy8ExQ4L2UBrKEE= X-Received: by 2002:adf:de91:: with SMTP id w17mr6459370wrl.84.1605315139041; Fri, 13 Nov 2020 16:52:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Felipe Contreras Date: Fri, 13 Nov 2020 18:52:08 -0600 Message-ID: Subject: Re: Bug with unset variables To: Roman Perepelitsa Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 47557 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Fri, Nov 13, 2020 at 2:52 AM Roman Perepelitsa wrote: > > On Thu, Nov 12, 2020 at 10:08 PM Felipe Contreras > wrote: > > > > On Thu, Nov 12, 2020 at 1:11 PM Roman Perepelitsa > > 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.) The two things are functionally *exactly* the same. In JavaScript if you don't declare foo, accessing it gives you the value of "undefined", and if you declare it and "unset" it, it also gives you "undefined". Exactly the same as in shell. You just don't want to accept they are functionally the same because you don't want them to be the same. > 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. Lisp doesn't allow defining variables without a value. > > 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. Once again: a distinction without a difference. https://en.wikipedia.org/wiki/Distinction_without_a_difference > 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. Yes, but you have avoided some of my strongest arguments, for example this: func () { [[ -n "$1" ]] && var=$1 dosomething ${var-other} } func () { typeset var [[ -n "$1" ]] && var=$1 dosomething ${var-other} } You have never explained how it makes sense that adding that extra line changes the behavior. > 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). And I've shown you how you are comparing apples to oranges. > 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. Exactly the same thing as in JavaScript, just s/nil/undefined/. Either way, "local x" in Lua does exactly the same thing as it does in Bash. When you compare apples to apples the behavior is exactly the same in all languages. Cheers. -- Felipe Contreras