zsh-users
 help / color / mirror / code / Atom feed
* Question with no answer, a="1+1"; $(( mathfun($a) ))
@ 2017-02-23  8:54 Sebastian Gniazdowski
  0 siblings, 0 replies; only message in thread
From: Sebastian Gniazdowski @ 2017-02-23  8:54 UTC (permalink / raw)
  To: zsh-users

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@fastmail.com


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-02-23  8:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23  8:54 Question with no answer, a="1+1"; $(( mathfun($a) )) Sebastian Gniazdowski

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).