From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18536 invoked by alias); 21 Oct 2015 18:01:34 -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: 20802 Received: (qmail 16540 invoked from network); 21 Oct 2015 18:01:32 -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 autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=T/C1EZ6Q c=1 sm=1 tr=0 a=vsFYQC4/11PqlKifmEOq9w==:117 a=vsFYQC4/11PqlKifmEOq9w==:17 a=N659UExz7-8A:10 a=FrNgu2ZQILlig7uE_GEA:9 a=pILNOxqGKmIA:10 Message-id: <5627D2F8.3000004@eastlink.ca> Date: Wed, 21 Oct 2015 11:01:28 -0700 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: suprise with -= References: <562483C9.1060602@eastlink.ca> <151019113517.ZM32739@torch.brasslantern.com> <562545DD.5020008@eastlink.ca> <151019172744.ZM558@torch.brasslantern.com> In-reply-to: <151019172744.ZM558@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit 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': 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. > 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.