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

Re: for loop 'bad math expression'



On Sun, Feb 4, 2024, at 11:37 AM, Ray Andrews wrote:
> I get that.  $(( abc ..... )) ... abc isn't a number therefore it's the 
> name of a variable.  However I did:
>
> % var=abc
> ... outside any (()) and the conversion happened 'retroactively' so to speak. 
>
> % var=path; print -- $var
> path
> ... 'path' is just a string, there's no implicit conversion to a 
> variable.

Of course there isn't, because there is no arithmetic context there.
If you'd run

	print -- $((var))

then "path" would have been referenced recursively.  (And you almost
certainly would have seen an error because the contents of "path"
are unlikely to form a valid arithmetic expression.)


> Ergo:
>
> %var=abc 
> ... seems to me the same.  Later on abc becomes an integer name, and 
> the string is lost

The string is never lost.  Inspect the raw value of "var"; it does
not change from "abc" unless you change it yourself.


> Anyway it goes back to my original speculation/question that implicit 
> promotions/conversions do happen

You still haven't demonstrated any situations where this occurs.
All your examples have been broken, and your conjectures confused.


-- 
vq




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