     Next: String Searching Up: NESL: A Nested Data-Parallel Previous: Deriving Complexity

Examples

This section describes several examples of NESL programs. Before describing the examples we describe three common operations. The -> binary operator (called read) is used to read multiple elements from a sequence.   Its left argument is the sequence to read from, and the right argument is a sequence of integer indices which specify from which locations to read elements. For example, the expression reads the p, a, l and e from locations 7, 0, 8 and 4, respectively. The read function can also be expressed as read(a,i) instead of a -> i.

The <- binary operator (called write) is used to write multiple elements into a sequence.   Its left argument is the sequence to write into (the destination sequence) and its right argument is a sequence of integer-value pairs. For each element (i,v) in the sequence of pairs, the value v is written at position i of the destination sequence. For example, the expression writes the s, d and space into the string "an example" at locations 4, 2 and 3, respectively (space is a constant that is bound to the space character). The write function can also be expressed as write(d,iv) instead of d <- iv.

Ranges of integers can be created using square brackets along with a colon.     The notation [start:end] creates a sequence of integers starting at start and ending one before end. For example: An additional stride can be specified, as in [start:end:stride], which returns every stride integer between start and end. For example: The integer end is never included in the sequence. Figure: Possible implementation for several of the NESL\ functions on sequences.

Using these operations, it is easy to define many of the other NESL\ functions. Figure 5 shows several examples.     Next: String Searching Up: NESL: A Nested Data-Parallel Previous: Deriving Complexity

Jonathan Hardwick
Tue Nov 28 13:57:00 EST 1995