From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Infinite recursions in math evaluation
Date: Fri, 13 May 2011 23:37:37 +0200 [thread overview]
Message-ID: <BANLkTimXmy78=PFk_5Hm0j+4owt0Fb=BNg@mail.gmail.com> (raw)
I was trying to do something completely different and noticed that
this causes an infinite recursion:
a=a; ${(#)a}
and this doesn't
${(#):-a}
(and surprised me by cding into my first $cdpath entry, turns out it
returned a null character, and that does that with autocd on.)
The thing seems to be the variable name having the same name as the
value of it. Aha, actually a=a; $(( a )) crashes in the same way. (On
a machine with a presumably less optimized/buggy compile, it does
print "zsh: math recursion limit exceeded" instead of crashing). Is it
simply a user error? I wouldn't expect either of these expressions to
recursively look up values of the parameter until it encountered a
number, but this is indeed what happens:
% a=b; b=c; c=d; d=e; e=f; f=5; echo $(( a ))
5
bash does the same...
It seems to be of somewhat random utility though:
a='b c'
b='5 +'
c='5*3'
echo $(( a ))
zsh: bad math expression: operator expected at `c'
a='b+c'
echo $(( a ))
zsh: bad math expression: operand expected at `'
b='55+32'
echo $(( a ))
102
I scanned quickly through the "Arithmetic Evaluation" section and
found nothing suggesting that this should happen. It is also perhaps
somewhat unclear from the description of the (#) flag in the manpage
that it causes the same eval as in $(( )), it simply says the
resulting words are parsed as numeric expressions. Executing echo
${(#):-'foo=bar, bar=65, foo'} twice outputs A the second time btw.
I would not be opposed to just describing this behaviour in the
manpage (if I didn't just miss a huge section that describes it
again.. :)
--
Mikael Magnusson
PS What I originally actually wanted to run was $(( #a )), but I
remembered the wrong syntax.
next reply other threads:[~2011-05-13 21:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-13 21:37 Mikael Magnusson [this message]
2011-05-14 4:36 ` Bart Schaefer
2011-05-14 9:03 ` Mikael Magnusson
2011-05-14 18:00 ` Bart Schaefer
2011-05-14 18:09 ` Mikael Magnusson
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='BANLkTimXmy78=PFk_5Hm0j+4owt0Fb=BNg@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=zsh-workers@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).