Skip to content

Commit 700195a

Browse files
committed
add subsection aboyt empty arrays
1 parent c78bc9b commit 700195a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/reference-manual/expressions.qmd

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,22 @@ array[2, 3] int b = { { 1, 2, 3 },
334334
{ 4, 5, 6 } };
335335
```
336336

337+
#### Empty arrays {-}
338+
337339
The empty array expression (`{ }`) is not allowed. See more about restrictions on array expressions in subsection [Restrictions on values](#array-expressions).
338340

341+
If needed, it is possible to create an empty array with
342+
```stan
343+
rep_array(e, 0)
344+
```
345+
where the first expression `e` determines the type of the array. For
346+
example, `rep_array(0.0, 0)` returns an empty real array of type
347+
`real[]`, whereas `rep_array({123}, 0)` returns an empty two
348+
dimensional integer array of type `int[ , ]`. Only the type of the
349+
first argument is used, so the integer arrays `{123}` and `{0}`
350+
produce equivalent values.
351+
352+
339353
### Array expression types {-}
340354

341355
Any type of expression may be used within braces to form an array
@@ -418,13 +432,6 @@ zero-element array.
418432
array[0] int a; // a is fully defined as zero element array
419433
```
420434

421-
If needed, it is also possible to create an empty array with
422-
```stan
423-
rep_array(0, 0)
424-
```
425-
where the type of the first argument determines the type of the array
426-
(e.g., real or int).
427-
428435
#### No zero-tuples or one-tuples {-}
429436

430437
There is no way to declare or construct a zero-tuple or one-tuple in

0 commit comments

Comments
 (0)