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

Re: suprise with -=



On Oct 20,  7:55pm, Ray Andrews wrote:
} Subject: Re: suprise with -=
}
} On 10/19/2015 05:27 PM, Bart Schaefer wrote:
} > 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
} 
} Then what does 'integer' or 'typset -i' do?

They declare that the internal representation of the variable should be
an integer, so that integer formatting may be applied when the variable
is converted back to a value with $first.

} I can't help but wonder what was going on in the minds of the guys who
} coded the first shells

The first shells didn't have integers or arrays at all.  They had only
strings, and a few (external) programs like "expr" that could interpret
strings of digits as numbers.

Arrays came next and numbers/math last of all, so numbers must conform
to the rules established when the shell was strings-only.  Shells were
never intended to look or behave anything like C (well, except for csh,
but it was only supposed to look like C, not act like it, and it got a
lot of other things wrong).



Messages sorted by: Reverse Date, Date, Thread, Author