* Numbers with leading _
@ 2022-11-21 16:22 Mikael Magnusson
2022-11-21 16:27 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Mikael Magnusson @ 2022-11-21 16:22 UTC (permalink / raw)
To: zsh-workers
I was playing with extending hasbraces+xpandbraces to allow _ in
numbers via zstrtoul_underscore, and noticed that in normal math
context, this happens:
% echo $(( _1000 ))
0
% a=(1 2 3); echo $a[_1]
% a=(1 2 3); echo $a[1_]
1
but my modifications worked fine:
% echo {_999_.._1_0_0_1_}
999 1000 1001
Obviously there's no real reason why anyone should want to specify a
number with a leading underscore but is there a reason to reject it in
the normal math context, and should we print some kind of error when
we do it rather than silently parse it as a 0?
I didn't yet try to track down where this rejection happens, but it's
at least not in zstrtoul_underscore.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Numbers with leading _
2022-11-21 16:22 Numbers with leading _ Mikael Magnusson
@ 2022-11-21 16:27 ` Peter Stephenson
2022-11-22 5:07 ` Mikael Magnusson
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2022-11-21 16:27 UTC (permalink / raw)
To: zsh-workers
> On 21/11/2022 16:22 Mikael Magnusson <mikachu@gmail.com> wrote:
> I was playing with extending hasbraces+xpandbraces to allow _ in
> numbers via zstrtoul_underscore, and noticed that in normal math
> context, this happens:
> % echo $(( _1000 ))
> 0
> % a=(1 2 3); echo $a[_1]
>
That's a reference to the variable $_1 (which obviously isn't set).
pws
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Numbers with leading _
2022-11-21 16:27 ` Peter Stephenson
@ 2022-11-22 5:07 ` Mikael Magnusson
0 siblings, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2022-11-22 5:07 UTC (permalink / raw)
To: Peter Stephenson; +Cc: zsh-workers
On 11/21/22, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
>> On 21/11/2022 16:22 Mikael Magnusson <mikachu@gmail.com> wrote:
>> I was playing with extending hasbraces+xpandbraces to allow _ in
>> numbers via zstrtoul_underscore, and noticed that in normal math
>> context, this happens:
>> % echo $(( _1000 ))
>> 0
>> % a=(1 2 3); echo $a[_1]
>>
>
> That's a reference to the variable $_1 (which obviously isn't set).
Aha, that indeed does make sense now, thanks.
% _1000=5
% echo $(( _1000 ))
5
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-22 5:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 16:22 Numbers with leading _ Mikael Magnusson
2022-11-21 16:27 ` Peter Stephenson
2022-11-22 5:07 ` Mikael Magnusson
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).