From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1282 invoked by alias); 21 Oct 2015 18:50:24 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20804 Received: (qmail 20951 invoked from network); 21 Oct 2015 18:50:22 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1445453032; bh=SP5s3KFO5mUezDn48xUGJoKXhuUwAs6XL75eO9PD7AY=; h=From:To:In-Reply-To:References:Subject:Date; b=aN8rmP9+AmOIDZIgRhWMHbfvEReqdTiqj6yO1xRbKX4W8qCxxbi13VmyQnwLwtSx5 RKK4i9pwMupJ48Ojk7aTwoCtLsyyi50w+M//vYzURMD/tKPxmwQXry8TZhf07gapAH QO78FgUj4KZaGs8tYleW73bzo0S/71hy/QCSn3mA= From: ZyX To: Ray Andrews , "zsh-users@zsh.org" In-Reply-To: <5627D2F8.3000004@eastlink.ca> References: <562483C9.1060602@eastlink.ca> <151019113517.ZM32739@torch.brasslantern.com> <562545DD.5020008@eastlink.ca> <151019172744.ZM558@torch.brasslantern.com> <5627D2F8.3000004@eastlink.ca> Subject: Re: suprise with -= MIME-Version: 1.0 Message-Id: <970471445453032@web1h.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Wed, 21 Oct 2015 21:43:52 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r 21.10.2015, 21:02, "Ray Andrews" : > On 10/19/2015 05:27 PM, Bart Schaefer wrote: >> šThe parser doesn't know that "first" is an integer, or even that it's >> ša variable that was previously declared. > > That puzzles me. Have not all your examples demonstrated that the > parser is aware of the type of the variable and that it will perform > it's operations accordingly? > > šššštest2 () > šššš{ > > ššššššššinteger first=1 second=2 > > ššššššššthird=first+second > ššššššššprint A $third > ššššššššinteger third > ššššššššprint B $third > > ššššššššinteger fourth=first+second > ššššššššprint C $fourth > > šššš} > ššššA first+second # 'third' is scalar so does the 'wrong' thing. > ššššB 0 # 'third' is now known to be integer by the 'print'. > ššššC 3 # 'fourth' is integer up front and remembered to > ššššbe so. > > I see very clearly that the type can change silently or sometimes not > change at all and just sorta 'do nothing': How is *parser* related? To make integer fourth=first+second set `fourth` to `3` it is *absolutely* not needed to parse this as integer(assign("fourth", plus("first", "second"))) . Just at the time of parsing you parse it as integer(assign("fourth", "first+second")) and at the time of *execution* you evaluate `first+second` as an expression. > > šššštest1 () > > šššš{ > > ššššššššinteger first=1 > ššššššššstring1=foo > > ššššššššfirst+=string1 > ššššššššecho ${(t)first} > ššššššššecho "$first" > > šššš} > ššššinteger-local > šššš1 # The addition does nothing at all, but no error is thrown. > > ... and "${(t) ...}" is surely the demonstration that types are > remembered? I'm makinga deep error here, probably. Remembering types has *absolutely* nothing to do with parsing. ${(t)V} is executed at runtime, after parsing. Neither parser needs to know what is `V` and whether it is defined. Basically this happens in every dynamically typed language. (Though most statically typed language developers do not think that parsing two constructs differently depending on variable types is not a good idea; this does not prevent e.g. `foo.a` to be an error due to incorrect `foo` type, but this is checked after parsing stage and is always read as something like `getattr("foo", "a")`.) > >> šThe first shells didn't have integers or arrays at all. They had only >> šstrings, and a few (external) programs like "expr" that could interpret >> šstrings of digits as numbers. > > Thanks. These 'history lessons' are invaluable (to me, anyway). If > anything besides strings were never anticipated in the original design > of shells,then integers would bea 'tack on' and one could see that the > whole issue of declarations/typing would behandled poorly. The lesson > is that one must be bloody careful. OTOH, whereas in Cif one wants to > force a typecast it's a > labor, whereas in zsh one can do it not onlyeffortlessly, but even > invisibly. > Powerful but dangerous.Caveat emptor.