Merge pull request #4563 from krux02/spec-update

updadet doc/manual array construction syntax
This commit is contained in:
Andreas Rumpf 2016-08-03 23:55:04 +02:00 • committed by GitHub
commit 186bfe4475
2 changed files with 7 additions and 5 deletions

View file

@ -19,10 +19,8 @@ other binary operators are left-associative.
proc `^/`(x, y: float): float = proc `^/`(x, y: float): float =
# a right-associative division operator # a right-associative division operator
result = x / y result = x / y
echo 12 ^/ 4 ^/ 8 # 24.0 (4 / 8 = 0.5, then echo 12 ^/ 4 ^/ 8 # 24.0 (4 / 8 = 0.5, then 12 / 0.5 = 24.0)
12 / 0.5 = 24.0) echo 12 / 4 / 8 # 0.375 (12 / 4 = 3.0, then 3 / 8 = 0.375)
echo 12 / 4 / 8 # 0.375 (12 / 4 = 3.0, then
3 / 8 = 0.375)
Precedence Precedence
---------- ----------

View file

@ -435,7 +435,9 @@ has the same type. Arrays always have a fixed length which is specified at
compile time (except for open arrays). They can be indexed by any ordinal type. compile time (except for open arrays). They can be indexed by any ordinal type.
A parameter ``A`` may be an *open array*, in which case it is indexed by A parameter ``A`` may be an *open array*, in which case it is indexed by
integers from 0 to ``len(A)-1``. An array expression may be constructed by the integers from 0 to ``len(A)-1``. An array expression may be constructed by the
array constructor ``[]``. array constructor ``[]``. The element type of this array expression is
inferred from the type of the first element. All other elements need to be
implicitly convertable to this type.
Sequences are similar to arrays but of dynamic length which may change Sequences are similar to arrays but of dynamic length which may change
during runtime (like strings). Sequences are implemented as growable arrays, during runtime (like strings). Sequences are implemented as growable arrays,
@ -460,6 +462,8 @@ Example:
x = [1, 2, 3, 4, 5, 6] # [] is the array constructor x = [1, 2, 3, 4, 5, 6] # [] is the array constructor
y = @[1, 2, 3, 4, 5, 6] # the @ turns the array into a sequence y = @[1, 2, 3, 4, 5, 6] # the @ turns the array into a sequence
let z = [1.0, 2, 3, 4] # the type of z is array[0..3, float]
The lower bound of an array or sequence may be received by the built-in proc The lower bound of an array or sequence may be received by the built-in proc
``low()``, the higher bound by ``high()``. The length may be ``low()``, the higher bound by ``high()``. The length may be
received by ``len()``. ``low()`` for a sequence or an open array always returns received by ``len()``. ``low()`` for a sequence or an open array always returns