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 6916 invoked from network); 12 Nov 2020 08:46:32 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 12 Nov 2020 08:46:32 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605170792; b=a3yb1hCYA0Mb4l0mXQINBFYuGSyxrsQNBgorYy3IErsTJOFD3S5JwRdfg2T4AZvNLYylJ5HChM pCaQfZ9vELR56WdgwcIgLPLbdFeFfH0XW2OVEoNzyvyY4tuJjM3Wr0cPXv5Bb0CC2OREKnv3sz TAdKibYdlzBUwSG5r8RJqa4c+FbjSOgP5X7xiuRpkg7GFgq41PCsPRue2iUKTNMmWp9ISmsnPK M/6u4dSzBs8pM6+rWBP7WA+xNgdkf0iKWYK9IDlBmVHjZtTa14Bz1r3BnY/y/ChD6DPvDbeyY9 gb60EKJKPbN9YnYscLo46eAggrV5gi6XZDtFX36wv3l+KQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-il1-f181.google.com) smtp.remote-ip=209.85.166.181; 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=1605170792; bh=c039ho2PbDv3XhhYDwtDbtR5v9XZLYFR8EldAVvAnLA=; 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=UHi0EXuPKjoWCd0B//9ZVmPxAN0Mt8+szEGvKTeQL84HtpY+bzv87kNf01Bpiql1RUDA+TWx0Q 6TSUB2pnlIO+bgqJ+b/I9drs1TuEmHr2gFYHr3E+Q2fPA/7nqO9GlCkBj0BjyMsK6xriRi+bwf +BBK6CuKzdVz2SnrV1P5zKBrNBnsn1KiXVYAbDw2NbUfhRZ3qiENBwnRPFpFfyZ1STHfDENE/v 8vjEeEXv6Xlm9HS5AiDY+zpnUkjA/v/CKODYwDYoUv+aRAGVB1B+uDh9SX0MZfIzZIDlLMLfB4 701Z/e20ehTA0WAUjSr4lnnCgTgbPKxziOrxeVazDclzsg==; 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=v3aj9QRjoKCjAI+KX2Iza0/Z0yrpPkp7ThWmZtHBeFA=; b=jz8cHIZ3DtUsmCSuz7TSVb3GKd ipBvwsqIbd7UAq5oLGDUDkR0NCVNLO6dsxCHukv0V90PxeN8f0+NNJTJWwQ3PUoITO3kyl/7r2KZi 0WiSegAGg6LPBIQKmhwkB4iwgc1QlpKaYNNae4+2Rkt+xJSY1b60quc+VpfibXtLaUCd6SVuv7pFr v7vbXwpleH+xI0gyC4W892wWFdJrfIlLGxzRfyemrqmcq2oVkudp2A0PtGPBDZ+BX0XxTTD7onwBa J5kDK2Fxq4Y7VEEjNjQpuRHfdCJqyA1aZZs6peN0dTTh4s6npBiUAaRjEG/Reh/AwU6KFksOzQli/ LNecpByA==; Received: from authenticated user by zero.zsh.org with local id 1kd8FQ-0006Y8-IE; Thu, 12 Nov 2020 08:46:28 +0000 Authentication-Results: zsh.org; iprev=pass (mail-il1-f181.google.com) smtp.remote-ip=209.85.166.181; 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-f181.google.com ([209.85.166.181]:46490) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kd8F7-0006OX-CT; Thu, 12 Nov 2020 08:46:10 +0000 Received: by mail-il1-f181.google.com with SMTP id a20so4494593ilk.13 for ; Thu, 12 Nov 2020 00:46:09 -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=v3aj9QRjoKCjAI+KX2Iza0/Z0yrpPkp7ThWmZtHBeFA=; b=LCOLXlarGsgRwyqzXp4XwnicYYviq+Bb+8n6pEExkvRo73qQQRDpr9Wf8fDjMubkj9 m9s5lfV2WtUMPABH/hTPkQn98+RCGBGbWM4XdGmNCgxEOzL0XXCPl50pizNCvcVpAUA7 tEboLxZNDqSzTZQLOMQJrisD+Un6Wj76AgLMoqCGpWpikAPz1yH1Pasb1axR/5eJYOoK RdMp30l9AupsYsf/2xrKDtxvT4gUuiLFKlq/hVB8joGVxc5HoluGPDJFGVTe+8M3IerU RiYGYhm4yvCFS629AMiEplJgiEZYet07Fe9P6hgVMoLfp7/c3eOorABnlKjBpIDXdkBC f75g== 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=v3aj9QRjoKCjAI+KX2Iza0/Z0yrpPkp7ThWmZtHBeFA=; b=Zks6c7MmdgWQLT0ahNjs/EHwI+nVeP8tUD2p/+hdNXel4/VD4Q+ndLUTr4YyNuz2e9 LaQM/XldLGCn7DNkl4eO2zL+S9peLILlT3lI03hAiHhyORcDLaZSZkXMSBMQcizCN11u YrIyuGhMP6yPmj/+ISQZona+E21HU/KAdXdNOiyQl1eoTPFxG9GOHmhlTPlJEeoQKci+ k992J02RP9CRV+eekNPgFvUxWKrymMEo7519Oz3ZeuawCFamQ6jlDqGYwOSgUEuv50Ba YDNdOWijU89mp6VBHFyvdlxi53SqENPfHnDI5NtAKRNzvYUII6Hvoa3Ojawxd2TU/HvH O/zQ== X-Gm-Message-State: AOAM532wWWhwNNIwDBSz7zOHyxoQ3Aen8PGB9nuLymCb+L0g74ZZiHJZ k+Cg4MaMtxns1rMEOLCeXldff344akG7BStr59A= X-Google-Smtp-Source: ABdhPJx9M+PlaY5Cy1BpQxkFAToB9j9x1rzhqlXIZLLoX3rvMEyix5XWBgyT3Q/ikQRkIBhmxaOgU9Zpo069vLbN6ow= X-Received: by 2002:a92:d60b:: with SMTP id w11mr21879690ilm.151.1605170767923; Thu, 12 Nov 2020 00:46:07 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Thu, 12 Nov 2020 09:45:56 +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: 47544 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 Wed, Nov 11, 2020 at 9:42 PM Felipe Contreras wrote: > > > typeset -i var > > echo $var > > In this case it might make sense to initialize to 0, since that's the > only sensible default for an integer, but consider these: > > typeset -i int > typeset -a array > typeset -A hash > typeset -F float > > 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. 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. 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. In sum, what zsh does makes sense to me and feels natural and consistent with other languages I know. 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. Roman.