From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: suprise with -=
Date: Mon, 19 Oct 2015 17:27:44 -0700 [thread overview]
Message-ID: <151019172744.ZM558@torch.brasslantern.com> (raw)
In-Reply-To: <562545DD.5020008@eastlink.ca>
On Oct 19, 12:34pm, Ray Andrews wrote:
}
} [...] declare variable types, which is what I'm trying to do with
} 'integer' and after that I'd expect both increment and decrement to
} behave the same way.
The parser doesn't know that "first" is an integer, or even that it's
a variable that was previously declared. This is perfectly legal:
if (( RANDOM % 7 ))
then integer first
else declare first
fi
first+=second
(Which is why I'm inclined to say it ought to always be string context
when not explicitly math context, but it's probably way to late for that.)
} I'd consider it very rude for any forcible conversions to occur.
} Better an error, tho again once one has declared an integer one might
} expect one's operators to behave consistently.
Note:
torch% integer first=1 second=2
torch% first+=(second)
torch% echo $first
1 second
This has silently forced $first to change into an array because of
explicit array context; it did not interpret "(second)" as arithmetic
parens.
Also just to mess things up a bit more:
torch% integer first=1 second=2
torch% third=first+second
torch% print $third
first+second
torch% integer third
torch% print $third
3
If something has a string value and you re-declare it integer, it does
math on its string value. Doesn't happen for array to integer.
next prev parent reply other threads:[~2015-10-20 0:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-19 5:46 Ray Andrews
2015-10-19 18:35 ` Bart Schaefer
2015-10-19 19:34 ` Ray Andrews
2015-10-20 0:27 ` Bart Schaefer [this message]
2015-10-21 2:55 ` Ray Andrews
2015-10-21 3:52 ` Bart Schaefer
2015-10-21 18:01 ` Ray Andrews
2015-10-21 18:43 ` ZyX
2015-10-22 15:29 ` Ray Andrews
2015-10-22 15:43 ` ZyX
2015-10-22 16:02 ` Ray Andrews
2015-10-22 23:56 ` Bart Schaefer
2015-10-23 7:34 ` Daniel Shahaf
2015-10-21 18:46 ` Bart Schaefer
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=151019172744.ZM558@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--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).