1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-01 17:24:50 +01:00

Norbert Koch: 15954: fix inconsistency of variable name in example.

This commit is contained in:
Clint Adams 2001-10-06 17:40:26 +00:00
parent bf15727e38
commit 7668a03cb2
2 changed files with 39 additions and 5 deletions

View file

@ -1,3 +1,8 @@
2001-10-06 Clint Adams <clint@zsh.org>
* Norbert Koch: 15954: Doc/Zsh/arith.yo:
fix inconsistency of variable name in example.
2001-10-05 Clint Adams <clint@zsh.org>
* 15941: Completion/Unix/Command/_mount:

View file

@ -29,7 +29,7 @@ is equivalent to
example(let "val = 2 + 1")
both assigning the value 3 to the shell variable tt(foo) and returning a
both assigning the value 3 to the shell variable tt(var) and returning a
zero status.
cindex(bases, in arithmetic)
@ -43,6 +43,33 @@ The var(base)tt(#) may also be omitted, in which case
base 10 is used. For backwards compatibility the form
`tt([)var(base)tt(])var(n)' is also accepted.
It is also possible to specify a base to be used for output in the form
`tt([#)var(base)tt(])', for example `tt([#16])'. This is used when
outputting arithmetical substitutions or when assigning to scalar
parameters, but an explicitly defined integer or floating point parameter
will not be affected. If an integer variable is implicitly defined by an
arithmetic expression, any base specified in this way will be set as the
variable's output arithmetic base as if the option `tt(-i) var(base)' to
the tt(typeset) builtin had been used. The expression has no precedence
and if it occurs more than once in a mathematical expression, the last
encountered is used. For clarity it is recommended that it appear at the
beginning of an expression. As an example:
example(typeset -i 16 y
print $(( [#8] x = 32, y = 32 ))
print $x $y)
outputs first `tt(8#40)', the rightmost value in the given output base, and
then `tt(8#40 16#20)', because tt(y) has been explicitly declared to
have output base 16, while tt(x) (assuming it does not already exist) is
implicitly typed by the arithmetic evaluation, where it acquires the output
base 8.
When an output base is specified using the `tt([#)var(base)tt(])' syntax,
an appropriate base prefix will be output if necessary, so that the value
output is valid syntax for input. If the tt(#) is doubled, for example
`tt([##16])', then no base prefix is output.
Floating point constants are recognized by the presence of a decimal point
or an exponent. The decimal point may be the first character of the
constant, but the exponent character tt(e) or tt(E) may not, as it will be
@ -84,12 +111,14 @@ Mathematical functions can be called with the syntax
`var(func)tt(LPAR())var(args)tt(RPAR())', where the function decides
if the var(args) is used as a string or a comma-separated list of
arithmetic expressions. The shell currently defines no mathematical
functions, but modules may define some.
functions by default, but the module tt(zsh/mathfunc) may be loaded with
the tt(zmodload) builtin to provide standard floating point mathematical
functions.
An expression of the form `tt(##)var(x)' where var(x) is any character
sequence such as `tt(a)', `tt(^A)', or `tt(\M-\C-x)' gives the ascii
sequence such as `tt(a)', `tt(^A)', or `tt(\M-\C-x)' gives the ASCII
value of this character and an expression of the form `tt(#)var(foo)'
gives the ascii value of the first character of the value of the
gives the ASCII value of the first character of the value of the
parameter var(foo). Note that this is different from the expression
`tt($#)var(foo)', a standard parameter substitution which gives the
length of the parameter var(foo). `tt(#\)' is accepted instead of
@ -139,7 +168,7 @@ retain that type either until the type is explicitly changed or until the
end of the scope. This can have unforeseen consequences. For example, in
the loop
example(for (( f = 0; f < 1; f += 0.1 )); do;
example(for (( f = 0; f < 1; f += 0.1 )); do
# use $f
done)