OEP

102

Title

Array constructors

Summary

Provide syntax for array literals based upon replicated expressions.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2001-10-08

Keywords

language arrays constructors literals replicators

Array constructors allow arrays to be created using a replicator and an expression. An example of this is:

[10]INT array:
SEQ
  ...
  array := [i = 0 FOR SIZE array | f(i)]
  ...

where "f()" is some expression, which might or might not involve "i".

Internally, the array constructor is turned into a VALOF process, so array-constructors may be used as parameters, or anywhere an expression is valid. The (obvious) limitation here is that array-constructors may not cause side-effects. The non-obvious limitation is that the count must be a compiler-known constant. This will be fixed at some point in the near future. The STEP addition may also be used in array constructors. The general syntax for this type of expression is:

"[" <repl> "=" <start> "FOR" <count> [ "STEP" <stride> ] "|" <expr> "]"

The line can be broken after the "|" to avoid things getting too long. A more extreme example of array constructors might be:

PROC show.3d (VAL [][][]INT n, ...)
  ...
:

...
SEQ
  show.3d ([x = 0 FOR 10 | [y = 0 FOR 10 | [z = 0 FOR 10 |
           ((x - z) * (y + z)) ]]])
  ...

INITIAL declarations now permit these to be used with dynamic MOBILE arrays. For example:

INITIAL MOBILE []INT x IS [i = 0 FOR 100 | foo(i)]:
...

OEP/102 (last edited 2007-09-26 23:46:23 by ats1)