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 8604 invoked from network); 13 Nov 2020 08:52:35 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Nov 2020 08:52:35 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605257555; b=xRVNS4Gg9Z8cQwqCI44tPNBHFOT4YiC0cyVZVVep2KP84ymizzu7/fM1Od+/eQHNRg+5owQQ95 UOtE9CkVfMaYK5CnD0YLm4T8sikjTUiGqZwYZ3BAlHp6s5qVPkO122GUeatHHNLEkPTa2yemeW CtEZOZ5v4qeKufCKqqvtBmMnGH5E5aTrYB++5HOiiMb512IneXyKw6F5XFdrwKKeqE9JLrt+8N JiEFkNrrykNwKF3JJLXzH0HO70NCsYgNsJEnE2eqrBZOlqPrPtdXwy8kI60pPmXg0qg8Ie8cSZ jKwcUoFWCHtNXy4GhbMk94hYEQKv3BwUzF36Q5bqdD2uug==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-il1-f178.google.com) smtp.remote-ip=209.85.166.178; 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=1605257555; bh=mb3R2JHBOzu6dG7qvvDCpLzP9ed++syLFocLJjPgFS8=; 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=PNgJ2M2fY/uFfwDD9ezy7Dk0dvXfY5mkBPnp5cspPBYcDC2e2KsVUgxUvGX1SZbnLhGzQuOIGJ s/n7fzSZ6ynbBIxfhdI63c/fYKEpg/T//e/rvn0EGIuXW2PliEULoXptyr7tgcJpLPp5FQ19Xz eoBJDFQShJiMGmi+xBDfZcuwnTqEGXd/7bl6Pwr/ddrkPeH8ZTvJIdlp5L6SmYscDUsuwbgy2s PMHi7/ewKhMQhkmXSPUUPL09Q+E8LgdupYD1SvtyZJ/N5N+7Tn/LLSW0A8E2pxUoRuMesGBYSk dpYclGv779o3V0d2a96+2dvkTsek3yZ3BF94tTe3tSGfEA==; 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=uss605/wC7t+K2wn35Y7s3pA5RNowad5q4+OFqxBVgw=; b=O1A7LcmRw4ennlAXNp1TMtUphL h40YTjukoE1DhQ6osqBnnMvgN8h5AyUWywX4vk/FZhtbN4YEQ+idx+xBHIr1ZhKpJYcSqdmu8VWrM GPymGg6HgocYiScW47sMjUJilRrVV8BY0cvHhSmk4znRMSP0gffBzyMCRCmSM5xEuHhkErxJZCdu+ IEgVPAYc6+InQAEj2Cwn703IHUUdT4pa7CcfCzC4WjrV3Mx/gOI1Gazw4wuZG5twFVsK8lcUFWkBW JWoZTw/55yXKlj3MTtcRhO4Ml05vXe2cicpif0mNzjgU4NI8Xj/TzGSeLQx7jWDLnQ0jkTmYrDbiI gJOHwLVA==; Received: from authenticated user by zero.zsh.org with local id 1kdUoo-000NUT-6p; Fri, 13 Nov 2020 08:52:30 +0000 Authentication-Results: zsh.org; iprev=pass (mail-il1-f178.google.com) smtp.remote-ip=209.85.166.178; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-il1-f178.google.com ([209.85.166.178]:42883) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kdUoU-000NKw-Ig; Fri, 13 Nov 2020 08:52:12 +0000 Received: by mail-il1-f178.google.com with SMTP id g15so7812854ilc.9 for ; Fri, 13 Nov 2020 00:52:10 -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=uss605/wC7t+K2wn35Y7s3pA5RNowad5q4+OFqxBVgw=; b=kd2VOPcwYRHlijXsb9rRFVFTJGOMff66neXtnpbpc5vO2biNGHG/86V7w2NJ0fEngH xXQyBunUALInNni4vzAl6qFTYBcmGBM0+TufuI7a8WokkI3zfGzhS4LV0TAM6P72i/A+ G0yRdweZpTd31o2KNP7Kn1z7IiXKjddq2wKq8PSpZe0MOBeIBPTi4JkDyYg90AE84Cdy kXCHHu2DPHJWKk3lIZ7JL5roqWaUCCw1L0ICk2zcUhZuDrmi+urA0JQn8cnL8HiY7Btt XAbBa/fjdE8LmlEFwk/ZQDSkrj5QAGKuP9V8pp1g2ABhWUJBZFchI98c41fWgOJ3Id80 ngMA== 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=uss605/wC7t+K2wn35Y7s3pA5RNowad5q4+OFqxBVgw=; b=DYYDx1N8awuzezum/fa7L4gYN8ecPDz33cDg4YuCnrruf3yw+DWrUq+dawFIo7E6Mw Q5HjG01Grkt0SJqZwKumqkNV9AUCI69l1jFOmhjjhMYDJ8Kk58XloaVS4ZtB+Ugh0nSN ktC42Cf6iN2YsCUDVC17Bzrs4yeYVds6PG86Ds6RD2h6QxhWQndxOPuwP5J48BMbH5nt MgF10Yp3iIgvOhkK9EMzC/KQmQvZu6EgmUejEUgulvr+7JVFgmgBfOwn+cKQLSWxxCAC z+2Yrqp7paefn3Or8rvQMGb0tGMuudtLYXUjVUCktgXP9xR5G1z6HBqFLHc3BWqGcxFk 3pGQ== X-Gm-Message-State: AOAM533sd+d42UYu6CcJw2QXRZXPmkDeCCVhE9vGkwAQ1icnpwN+ynrq iC6nQn5cM6fy0pvDWtyC165AYDDw1CaSct73Q2E= X-Google-Smtp-Source: ABdhPJwN5OB8BoZ2xmdiFIToCfsy55edNJjUAZtzNXPBez0sqjoyAmvZPyMkv6zjE2A8UUHZz+IvPM41kV4Cs7VPTlA= X-Received: by 2002:a05:6e02:92f:: with SMTP id o15mr1125878ilt.169.1605257528933; Fri, 13 Nov 2020 00:52:08 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Fri, 13 Nov 2020 09:51:58 +0100 Message-ID: Subject: Re: Bug with unset variables To: Felipe Contreras Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 47555 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 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.) 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.