Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: for x in * evaluates filenames as arithmetic expressions?



Einar Huginson wrote:
> Yes, that was indeed the case. I used `x' in an arithmetic for-loop earlier. 
> However, I didn't realize that this would implicitly impose a `sticky' type 
> for the variable. Now that I know, I'll be more careful in the future.

It's documented in the ARITHMETIC EVALUATION manual entry in zshmisc,
but fairly well down, so I don't suppose most people have read that far.
I expect the structure of the entry could be improved.

       If a variable is first assigned in a numeric context without previously
       being declared, it will be implicitly typed as  integer  or  float  and
       retain  that  type either until the type is explicitly changed or until
       the end of the scope.

The corollary is that if you always explicitly say "typeset x" before x
is ever used the variable will stay as a scalar.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author