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 7770 invoked from network); 12 Nov 2020 18:47:19 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Nov 2020 18:47:19 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605206839; b=sm40GxouOAg/882Swf9HVJfnwZjN+iEmUsVcR2pQ8lpQkxyFAqk3igOG7DfabPRNaQl+g5kcTO yPCoiWyl0/EQs0j/QNrF1PXhusVQv7ljKJT8xvclMz/dRL/umGIA0Xagnek9aAesIt6QFO4QpN VxtYucP0AaQx3X6D4HTnB5dYkdbKFBEUvtEyU2NAC5irsWmqcuxQhN0RS+OmTa+i98/BO8w8sI g6w7rLKZ1X/YfMSKXdZJ8/iKQxCAlNf322OSJ7L3A/nEe7EpIt4h8B0yhyF2bZfYu4AIeMYl5m +bkz84XCWD5rn2Ufa/t+JjlSSHoNW2wfus+JPaGPl56wUw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; 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=1605206839; bh=jlOZLaiqklC3XVHnbi4krIVpDsuSzpi24t8n42snh+E=; 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=Tu1lzvy7alBUhN4I+/p1YAP+StZs9MwFwUN0hCKrXSt7zXGUiBcxBfmQYjLrc3OAhklwDtsl0J zf8y7P+/UFtWrqWOMuJcPQDB9bW89gsvgRVPIQxnbYTLpWCl4nyDgcfcT3pGTxiRxDFF0agG36 6X3qgFUfNs7Ez4WfYSeIjM219qroM3ssaed+KiHLZe/OnqFCefWjB205Zm0CorL5cCprmxITyz y+5daadn6dYfvIaHSWM9sSLYRKL3ddVgQY4iRmvryjrOlfqsf6DmgaDT9p6mti7l2O2+3WVPt1 pV0egBTdQWJiSxg16h2HUlf/jKyIiavKMYjZRJ2vpm+u2w==; 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=dbcK+g8SQVqOqP94rdhY4tBp2fJlExTeeLj1cHLvsMg=; b=LI7dHPtNBNc6/+ks3xdlsv7jtl XcVsmc/7lJpmddcaKAbgniTIeptQL0xb7ZUkUDhw95CL9WNzEvzEqLWDLoz8Icfm+Kfoqg/EUaOoD TiBQfkLi5CR2DOh8gtU1pLeEJPvuiXHfFsO4mie6dOJQ5ilI3SR9soN2JfE+uhmGa//oueLHvnIJz p3WXt5nOAIhTHAsMC8rT2oVULzwW/mcqwX/USCPDCNtxF4TEb93s7b3BwE320sbr3n7hca8A06UlI OfBz4KnnmR5B0ByA198VjwcQc6cFnYEhD9cPflVqVnL0DSExM+fxObAVdCSWn2F4JKdwX1XP2GaaA wGEUQwqg==; Received: from authenticated user by zero.zsh.org with local id 1kdHcs-000N2L-CC; Thu, 12 Nov 2020 18:47:18 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wr1-f47.google.com) smtp.remote-ip=209.85.221.47; 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-f47.google.com ([209.85.221.47]:38441) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kdHcf-000MuU-0a; Thu, 12 Nov 2020 18:47:06 +0000 Received: by mail-wr1-f47.google.com with SMTP id p8so7129050wrx.5 for ; Thu, 12 Nov 2020 10:47:04 -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=dbcK+g8SQVqOqP94rdhY4tBp2fJlExTeeLj1cHLvsMg=; b=T8E1fTl15veuAqamOGpe67Zx6l153I4dqxJo69vjfxidZozbSKi7H9Di/kb+CENrzA gUjLWwVTLgNcSNuVesT0gybv6ntsi2twL9W5YIZOhtPmeNB7Q8B4kxE4bjWAbacZ19tx k7Yf0ZhBr5xXYa8padE91Id34YKHB72qiYE3dqZ4oFvgC+3VNHmapTq2hltqCv25YvNE ++P+ERUQQ2hBdYJUtZaO0zMPz4ppV2JfkK7eoyzNGFabLUFSUZIe8Xs9RqHtOkDI4bMT zCUpHi2VfimMnh8DVeIBEbNtBeCw5zdC3I2MtxbHZSUiDWnFJK7RlRE90Pu4dg/dEecO doDA== 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=dbcK+g8SQVqOqP94rdhY4tBp2fJlExTeeLj1cHLvsMg=; b=DdnNkmvnyv+aMeWUj/RRpaLix5xbClv6ojV4hi59Wfx9vEo6LQuUOSeeOxJ6/r/4bM 4iNiSQUoHmrDzoEYD1PVre6xycW9J5ZhWDTq3cOO0eH3cqevFJSuvnhUdf8FRdPQxefZ udrgxKuo5dSgNZNESo5rMz0u6Z6Vd5fY153N1Ek0l9+rcnb0VZEIFnpcq/vVQ7gwgeLd 4VMOGpHAEZnuuOvMMokF14JTMScUM+m9TK45mpdjd7r0lN3SpudyrkWk15cGVeh2+qLS i0edvLnm+ELJcDgPwf9Q4i8bvvZBnukSuJmEwaSGonfutGtNwFv2IrhV28AtjMUGYzPk McMQ== X-Gm-Message-State: AOAM532Nyhep3NzOx9Orph72NAneEo3LzzG4gX/WJvhzkrPwN6kZTzRf s2HgEY0Dmy8q0FAlfq+r+Gj77p7TXzgVSU0il+s= X-Google-Smtp-Source: ABdhPJywCeQFquEUeae64M8M7qO7kBfP80d3xXcc2TSVewNqR2wkjW1KqFKuUwZvZmM1xQyhR37W7tMWebEW9PuHPXo= X-Received: by 2002:adf:f041:: with SMTP id t1mr1029519wro.139.1605206824421; Thu, 12 Nov 2020 10:47:04 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Felipe Contreras Date: Thu, 12 Nov 2020 12:46:53 -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: 47548 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 2:46 AM Roman Perepelitsa wrote: > On Wed, Nov 11, 2020 at 9:42 PM Felipe Contreras > wrote: > > In all these it should be obvious what would be the sensible default, but this: > > > > typeset var > > Both bash and zsh are consistent. Regardless of the presence or > absence of a storage specifier, bash leaves the variable unset while > zsh sets it to the "natural" value of the parameter's storage type. By > natural I mean neutral w.r.t. +=. If `typeset -i var` was setting > `var` to zero while `typeset var` was leaving it unset, that would be > inconsistent. In my opinion this would be worse than the behavior of > bash and zsh. No. Zsh is not consistent. I did not type /typeset var=''/, I typed /typeset var/. > The fact that unset parameters are also called "null" in ksh/bash/zsh > invites confusion when comparing them to languages that can have > parameters with null *values*. Those null values are first-class > citizens. You can pass them as arguments to functions, store them in > arrays, etc. Shells don't have null *values*, they just have unset > parameters. 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. > Most languages (in fact, all languages I know) either don't have the > notion of an unset variable with function scope, or automatically give > all declared variables values. The closest equivalent to ksh/bash/zsh > I'm aware of is elisp because it also has dynamic typing and dynamic > scope. elisp has the same notion of an unset variable as ksh/bash/zsh > (they are called void in elisp). You can declare local variables with > `let` and unset them with `makunbound`. These behave like `typeset` > and `unset` in zsh -- in order to create an unset variable with > function scope, you need to declare it and then unset. Declaring the > variable without value won't do. So you don't know JavaScript (one of the most popular languages today)? > var v > typeof v 'undefined' Even in Python and Ruby the way you "declare" variables without a type is by setting them to the equivalent of the null value. This has *exactly* the same effect as "local x". Once again it's a distinction without a difference. In Swift you can declare a variable with the type "Any", and by default it has the nil value. Virtually all languages have a way of declaring a variable with a local scope, and *all* of them (including shell) have an idiom to do it without assigning an empty string (except zsh). > In sum, what zsh does makes sense to me and feels natural and > consistent with other languages I know. Carrying luggage without wheels also felt natural. Humans can get used to anything. You cannot tell me that if I originally have this: func () { [[ -n "$1" ]] && var=$1 dosomething ${var-other} } And I want to change the scope of the variable, so it's not set globally (which can be done in plenty of languages), and then I do this: func () { typeset var [[ -n "$1" ]] && var=$1 dosomething ${var-other} } It makes sense to *change* the behavior of the code. Can you? > That isn't to say that I > consider the behavior of ksh/bash incorrect. It's a bit surprising but > sensible. I could definitely get used to it. The strongest argument > for changing zsh is consistency with ksh and bash. The strongest > argument against it is that it'll break a lot of existing zsh code. > It's not my call but to me this looks like a no-go. This is a false dichotomy. Adding a setopt option for the new behavior doesn't break a lot of existing zsh code. Cheers. -- Felipe Contreras