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 23992 invoked from network); 12 Nov 2020 21:08:51 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Nov 2020 21:08:51 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605215331; b=KZ0emm4yABe1U3445NtPj8clVzr9WUSsF53XX6bqP2zgXBzmosqPOxevErbqlm5bZCK5R4fYQX ZBgkFAU0SeEMqYE5ibBHLs+s4dH/tkmpWA5CHIX7SIl/YKSS4eYcc4D798pLH/zEqeb+WyMCvC 370+ZkylO+F5TLuDnm/lrIlYsWgEUOLdibcjCE8oHAbkmwTgXdjo8UYYcBJaBu6mJIWQ6wjiRJ mVRzA3+JcQDqTLy03Sn45J+r6YhsZouXEQd51gTw+7XWnzZdP7qCYTfY6eLlWI40A7syXTSyHc 6hj9GrwgBExazYSl3k2+4ZR/XcaBZi6tAi1FTXUsHauAKg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f43.google.com) smtp.remote-ip=209.85.128.43; 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=1605215331; bh=G/2iU1I5DhpktFETUIXDBUwARSRvNM3uwfM0VCwOLcc=; 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=LUfIftKDKt/zqLVq6XothaKShZaPHgc5E0aGcog9hUOvzY2+EocQGxFl1dAWDKKJc8sNoXQZrj NUsuGZg7IrhdDARtVMoiXOLhjP6U1phk61Dm5caSQ4fVpzyE/UPSrdn0ZRPyp9pr/zIqz+qzMq XxwjSIbLGusQcl36s6lwLoUzGWuhVV9AU5xSIjHAjRZzSRJLkadDUQzYUMRLYTbxqDjTPr9xsb X+yyywdmZMZmtk+moL/HsotiWIrXqptnSU12ZaflZqoMBAYQJlTgEFkC/l7sl6jSAtkpydmnm3 NWonnYHiItUuHP25QkRG50gLTrCc/AhM+IYB6YSlwv9Qfw==; 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=07PsVKltD45KCebI/KNrEma6oJvby4UOEO6/YlBjBXY=; b=kN6OdrAgMN5QqvU0//Jkh/VIxG Ot2y97VaC8dSs9ECPKvpjmuC6ydyci0GWpKcu25mjoWVg21CMxTn9m/HM1jv9iP1jZL6DcEStMadH GPtMUQ5RxEmhBvD0Mndx1R/mdAkMLswSfnW7UVvG27TI46ad5os3z9BLiNb9msHdnbAEjpN+NJ/Jf 2vgpoOy6iteVR5G7ZYDo7PxX00aWR3MvfWiNB5qcR9LjlQEXYkYULQbVHtWClzx9HtWcAX423Z090 qi/GHCqCXGpUALz0C58XrzJC7KHZJn07ofuoL00sNVh06Vf4SeTIiJYST3PvfTfxaLSeHJ8YhjjMe GveOm0Nw==; Received: from authenticated user by zero.zsh.org with local id 1kdJpi-0003s4-Ob; Thu, 12 Nov 2020 21:08:42 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f43.google.com) smtp.remote-ip=209.85.128.43; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f43.google.com ([209.85.128.43]:54609) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kdJpR-0003iJ-9p; Thu, 12 Nov 2020 21:08:26 +0000 Received: by mail-wm1-f43.google.com with SMTP id d142so6437084wmd.4 for ; Thu, 12 Nov 2020 13:08:25 -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=07PsVKltD45KCebI/KNrEma6oJvby4UOEO6/YlBjBXY=; b=OsrObNAp+ekpASqMzYJkUZAg0vlSs6dFQL1QWwTM4Bm/PlAtjBlH/rmIFXledUNgHK s3+UjLgsnmIOK1urDNjtpkNuNGJ/EL06a/0I8YZDiUf76HyN75xUiGbjIX/wLrj9drvt Kv/1vHV7H+/vzrKTQLp9enHrkVhHUXVZbTkyi+//p8dVOq914EHY1u/KPzDPt+cL7ya/ u0/p6/my5QrC0mJSvMlX3Dp3jVUEzNz4mDl897/CtFSSDMlZDlLAW+2IecapGjjPGmAx D8JYKuTnVx6PiMGZBwcFa+iEX38w5AvUZUBeBKUq80ddK1unPPOxYezE0pu6d+JMxw0W XLnQ== 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=07PsVKltD45KCebI/KNrEma6oJvby4UOEO6/YlBjBXY=; b=EDGzvE/Qki9SYM45WCUGCJa9tXlLdwRTU8q2abamdLHAoeKRb4JloKeQIpG2PVaPo5 eQOVltDOlh1BgbgFHvvjqbd9BoYl/tJQEITsenMbFNuWKmdpFn9Uf5y4DefYO8GQJ5p9 ypg1mBQFI5mh+SwYCfc9sR1baHM53nYKIAKijs8j54KqGI4lwPrBjWdL536gCXY3g/BB zbhgEk/bpEXuK3PwQrby7CveMaI7+OxzEWWS3jqE1yXkU0VbqjAFwHRmcZnYf8WUWnRe 4UbzU0DoidgZAFpbgBn0cKPGGpH9zpZp/BLp3y5ktK0x8Eo4t4UJY6E20FH42G5pyC1l C/NQ== X-Gm-Message-State: AOAM533lhNMB9N9GnHAFnriLR8eO85J69FDQjGGm7+I79W65TwpDIE8j istwiiUv8XQoeuB9oqgtnc3EATZLbt0HbZU4D04= X-Google-Smtp-Source: ABdhPJz8u6Kj6dji4UgqkS/RxdmpZVZxfIREVWSqFVXy9pkCQGJ4PD56rWirDReCySjVDvZh0pFv3D0SgHni07HOzSc= X-Received: by 2002:a1c:4054:: with SMTP id n81mr1591863wma.48.1605215304906; Thu, 12 Nov 2020 13:08:24 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Felipe Contreras Date: Thu, 12 Nov 2020 15:08:13 -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: 47553 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 1:11 PM Roman Perepelitsa wrote: > > On Thu, Nov 12, 2020 at 7:47 PM Felipe Contreras > 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