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 24497 invoked from network); 11 Nov 2020 20:43:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Nov 2020 20:43:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605127395; b=SJRDH3Pnmh08LXYCURsyMh5EEty2MqpIcbxWulNlko9ucvx2nGIDePYBRbltjywT/dX8YqpY8O 3EtlxVdnOMrxvKd5uMAO5RA2flVFr9kzPmj+upd34n4KymgQH+RZrogt6No5Afjjw3tmx9sWkG mRYYuCFB+L13M9VJyEeh785XMe2YFUJoaPnTboYwG1n2vdvlpDfmCEViVKUW+4FlANKb9iDHIA N0PMg8Yu54wUppBlvfRwHoTefamphR/+IMrgcFP6mXqVv+MFgcWPDpOPMeIfLd4x3GgoYyu3Vg /kjZgEHCGxzcCvtzPUsBCnXc2SsCzzpgDS6zOHCC04NMkA==; 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=1605127395; bh=9dYwzyCroSMhPyOrSz/a35Jbfv7Js/iKcOAJDfpyE0A=; 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=xTT88PQ1iM5d6i3/OCJ2todtaMsxz6xtxWnlp7EaGYfWz4k1F/pju0N4se9VBT46sWUm7/yeKf GSKCu3PdwtQczeRb2REr2JzTusGbGtg3716tpBw51vy6PiVJbg5df38JW/5Ymg8Hq0/mAsG4bT ZsfUUFZUG6slQkLViFAvvJxVPraE+nvGNbf1oRdLY52o9SclsdG0L1/7VNhwZmo0mcoOHhqFhY deDwFGSD36A2Ua2nvyMdCSck2R/wOqGuD3067nwljd31PRy85Bn9hRmfCX5E5Xqcyl24TM/ERC s3GKqzQVosalPrTsC+NzVbJA24WrRPBMOxA3QPZ12+BXIg==; 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=0MzDQ94LgvXbNV5Q2vj+nukGuo/l+4FOzkZkRwq+0VY=; b=N+eC0k7jFQ51SJvWHL9X9J6SHo m3AGT21slnXHmVdyWz7+ztSDRUHyh4Pi/FoLjnGm/RoZPPDol8z5ZBLpY1l34umI8c8d0+P2j2bcN OKkkavWA7QZpD1cymlWk1vAfsMPF59nS3WH6B6nLGKLTxtsnDtnBPfeCHSA/iQ1uMBtrDgHgRgcAy ZY1Qr8QC3auAgN3+/QTIAoY7eTfezYu/JSrvVihLxqT1UZyLQAEuMa0h9DaTHgSj6cyLGyTgy7NNM a+9BcMdfenqewqEnhvKzdIqz2Y18pqPmLBJ3VxCsH3Z4K2uefs4aAHMCZEVfKQZ+FisCrkygwBddh aVdgD6+Q==; Received: from authenticated user by zero.zsh.org with local id 1kcwxW-000Ck1-AR; Wed, 11 Nov 2020 20:43:14 +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]:35579) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kcwxE-000CaF-8M; Wed, 11 Nov 2020 20:42:56 +0000 Received: by mail-wm1-f43.google.com with SMTP id w24so3582891wmi.0 for ; Wed, 11 Nov 2020 12:42:56 -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=0MzDQ94LgvXbNV5Q2vj+nukGuo/l+4FOzkZkRwq+0VY=; b=VESScTE7DAdjhx0wIoBDTFxYQ02KP1FQs3F8Xf+QW5sIMUcY3+4t+mpYa4hEKJvuUQ 82ImYeyyRAC2fiED3knwsEDF7zDbV6L2ZrwWpizaqI9GG3FdPKoj4ChdzuEM/20xF8ff JIQgL1gteNnjLAZs5TUxzr/f04+0LWHFsBUJG9/95LZaMIs/DXKH27s5I8HSnWHQ4WJ3 vXWFKZopuTMWbYK/s1lqM+EHU5YQ67+Wjwyokyf8XRG3egX5OgpGh0NOnNGc7+P2uEut nip9cD3FSgmtmG+qT2riHfrP0rKqt3ktXm/rh9ndipw7eignr0BItuTAXDpWv1aCC4ka ZyTg== 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=0MzDQ94LgvXbNV5Q2vj+nukGuo/l+4FOzkZkRwq+0VY=; b=uluygOSe8OoN+mqK/JvI/6HNPGn0KsiJBdRWxPmwkNr9poaESyiuwzZ8+GWysw6ppf fDK3NhuzJqs8N4DPA8n9mZe/9NjyPVduHOGby2rsqgbaDnlyXq7gvYEkYgqd3K6+W5B8 lA6T2cAbyei8BMWVLa3fo2oC7jpGaDkHVLxFStUiVmg5PXlJn2ncufVaBlrxMmBBD/Gw pldoHYFsSspSnv4/PBxP1VNZKOWlIgIQ0+X2aYyakCK6Nj6hzUlDXxvg/CkQp4fccRpI /WB+SvJR2laq2k/b3s7yEJNHy2qSrjNanaG66tSnbuwlFMEpJJvCEPdB20qWFEB9U6P0 vtAg== X-Gm-Message-State: AOAM530/EnocNjx4SCduVy9Hkak5xGNz8ZuF4aYM65K5mFGQ8XM90Zz3 pqb4eMpzixmmy8Ax6TG9mLsamgJo4Q35WS9T2VE= X-Google-Smtp-Source: ABdhPJxeGKO2lPNlD9GOAXiV6fv0OjSBhCihnnuzw8mGE/SnJclses5pwbwC7nmjvFSvQb3xu0PtWC3bXYA/BViPXt8= X-Received: by 2002:a1c:7215:: with SMTP id n21mr5915856wmc.173.1605127375563; Wed, 11 Nov 2020 12:42:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Felipe Contreras Date: Wed, 11 Nov 2020 14:42:44 -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: 47540 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 12:17 PM Roman Perepelitsa wrote: > > On Wed, Nov 11, 2020 at 7:03 PM Felipe Contreras > wrote: > > > > And what is the reason why this is not the default? > > I don't know, I'm fairly new to zsh myself. All I can say is that the > behavior of zsh feels more natural to me. Why would typeset var feel natural to be the same as typeset var="" ? If I wanted the second, I would type the second. Why does it feel natural to assign a value of a certain type, when no value was specified? > > Not only does this behavior differ from all other shells, but > > basically all languages. > > All languages? That seems exaggerated. How about this? > > int var; You are specifying a type. I obviously meant all languages where you can do the equivalent of "declare var" (without a type). That being said, the most similar to shell's "declare var" in C is "char *var" which defaults to null on most systems. > How many languages will set `var` to null here? Is it all of them? Pretty much, yeah. Do you want me to investigate and list them? Would the result of that investigation change the view of zsh developers? > In the morally-equivalent shell code, bash does but zsh doesn't: > > 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 Does not specify any type (or any value), so why would you assign a value of a possibly wrong type? It becomes more obvious when you print the declaration at each step: typeset var typeset -p var var=() typeset -p var In bash, we get something sensible: declare -- var # no type specified declare -a var=() Not so in zsh: typeset var='' # why a string? typeset -a var=( ) Not only is it inconsistent superficially, but also internally, since strings are considered "scalar", but that is just another word for "variable". An integer is also a scalar. So the word "scalar" doesn't really explain any type (only that it is a single value). > I don't know which of these languages conforms to the majority opinion > but neither can claim to do what *all* languages do. It is the most sensible thing to do, so I bet at least 99.9% of languages do this. It is also good, desirable, and consistent, that this: typeset var typeset -p var is a roundtrip, which happens in bash, but not so in zsh. > FWIW, I rely on this behavior of zsh in my code (namely, that `typeset > -i var` sets `var` to 0). That may make sense, because you are specifying a type, but "typeset var" doesn't specify a type. Apples and oranges. Cheers. -- Felipe Contreras