Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Question with no answer, a="1+1"; $(( mathfun($a) ))
- X-seq: zsh-users 22485
 
- From: Sebastian Gniazdowski <psprint2@xxxxxxxxxxxx>
 
- To: zsh-users@xxxxxxx
 
- Subject: Question with no answer, a="1+1"; $(( mathfun($a) ))
 
- Date: Thu, 23 Feb 2017 00:54:40 -0800
 
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h=	content-transfer-encoding:content-type:date:from:message-id	:mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=	mesmtp; bh=3WYmQvCbd+wLFEtuhk0GjUZBsno=; b=HUuJtRNGClj3K3bNvnbwy	+FLdeZiaZXz4EEoiZ1N8VdytWCz+uIlNa+Fe8d6DmOeki0DKfIto4ZEI2z4CW5MS	si2KQhInMgE1TA6IDHLV7swheIPRqL88aSictKgvpk6E0bO5v+odDIJG5TkHsJ3R	S5jH1IBcsnGGNnB5KaPeTY=
 
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=	messagingengine.com; h=content-transfer-encoding:content-type	:date:from:message-id:mime-version:subject:to:x-me-sender	:x-me-sender:x-sasl-enc; s=smtpout; bh=3WYmQvCbd+wLFEtuhk0GjUZBs	no=; b=BlB2O0GQvgVUSlhtRo1+QSbYrNbbmTm3taMvSBrtyBKYvgdeuwwvL6Ifq	Qwn3E6g5N+eYm9LP3K/jcmqiKUpSWs9m32EwBCCGinLk2EVtAHp4cIRevbglyyyR	7MsFUeawpL3N024d9GwSnA/j/DiPe0WSougJGjSqr3fBHDZDyo=
 
- List-help: <mailto:zsh-users-help@zsh.org>
 
- List-id: Zsh Users List <zsh-users.zsh.org>
 
- List-post: <mailto:zsh-users@zsh.org>
 
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
 
Hello,
I'm passing additional info with:
    local number="1+2"
instead of:
    integer number=3
The point is that first $number works normally in math context, but at
the same time it serves as string and I can do:
    number=$(( ${number%[-+]*} + 1 ))"${number##[0-9]##}"
This works, the hidden information is preserved, but it's not nice. I
would write math functions "first_addend" etc. to do:
    number=$(( first_addend(number) + 1 ))"${number##[0-9]##}"
But:
% mfun() { echo "dbg: $1"; }; functions -M mfun 1 1; val="1+2"; echo $((
mfun($val) ))
dbg: 3
3
This is probably a show stopper, but maybe I can accomplish the "nicer"
goal some other way, maybe even with math functions after all?
-- 
  Sebastian Gniazdowski
  psprint2@xxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author