Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Question with no answer, a="1+1"; $(( mathfun($a) ))



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