zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: for loop 'bad math expression'
Date: Sat, 3 Feb 2024 17:14:19 -0800	[thread overview]
Message-ID: <f228c732-d237-4597-b260-b28da72fd84b@eastlink.ca> (raw)
In-Reply-To: <CAH+w=7aznm0sBRqz4=Mo4q86oMzKrg0ktSEtFBGQupiWSV7WEg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]


On 2024-02-03 15:52, Bart Schaefer wrote:
> As Lawrence also suggested, I don't believe that happens.  If a
> parameter is created inside a math expression it will be assigned an
> appropriate numeric type, but the type of an existing scalar is not
> changed.

0 /usr/share/info 0 % var=abc; let var+=2; echo $var

2

... it looks like the shell is simply throwing away 'abc' and starting 
afresh with an integer and then incrementing it. And in the manual:

Note that assignment may implicitly change the attributes of a 
parameter. For example, assigning a number to a variable in arithmetic 
evaluation may change its type to integer or float, and with GLOB_ASSIGN 
assigning a pattern to a variable may change its type to an array.

> Context-awareness doesn't extend that far.  Globbing is already done
> and gone by the time "for" assigns its loop variable, nothing tells
> "for" where the loop values came from, and shell words on a command
> line carry no type information.

Sure.  I'm hardly surprised it wouldn't be practical, it was the most 
speculative sort of question.  And there really is no foul since my 
variable shouldn't have been an integer.  Actually, philosophically I'm 
opposed to most hand-holding anyway.  With experience I'd probably 
instantly detect what was going on there. But when you first bump into 
it, it seems inexplicable.

>
> You might try setopt warn_create_global to detect cases of names "leaking".
>
Never played with that.  Sounds useful.  As always my 'C-brain' tells me 
that indiscipline with variables is intolerable.



[-- Attachment #2: Type: text/html, Size: 2599 bytes --]

  reply	other threads:[~2024-02-04  1:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  3:39 Ray Andrews
2024-01-30  3:46 ` Ray Andrews
2024-01-30  4:04   ` Bart Schaefer
2024-01-30  4:06     ` Bart Schaefer
2024-01-30  4:17       ` Ray Andrews
2024-01-30 13:44         ` Ray Andrews
2024-01-30 14:30           ` Lawrence Velázquez
2024-02-03 23:52           ` Bart Schaefer
2024-02-04  1:14             ` Ray Andrews [this message]
2024-02-04  2:05               ` Lawrence Velázquez
2024-02-04  4:20                 ` Bart Schaefer
2024-02-04 16:08                   ` Ray Andrews
2024-02-04 20:56                     ` Lawrence Velázquez
2024-02-04 15:51                 ` Ray Andrews
2024-02-04 20:48                   ` Lawrence Velázquez
2024-02-04 21:09                     ` Bart Schaefer
2024-02-04 21:23                       ` Bart Schaefer
2024-02-05  2:10                     ` Bart Schaefer
2024-02-05  2:43                       ` Mikael Magnusson
2024-02-05  2:50                         ` Bart Schaefer
2024-02-05 15:21                       ` Ray Andrews
2024-02-05 15:48                         ` Mark J. Reed
2024-02-04 14:43               ` Mark J. Reed
2024-02-04 16:37                 ` Ray Andrews
2024-02-04 21:09                   ` Lawrence Velázquez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f228c732-d237-4597-b260-b28da72fd84b@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).