Back: 2. Using Array Syntax Forward: 2.2 Interpolating     FastBack: 2. Using Array Syntax Up: 2. Using Array Syntax FastForward: 3. Graphics         Top: Yorick: An Interpreted Language Contents: Table of Contents     About: About This Document

2.1 Creating Arrays

Including the span function introduced in the previous section, there are five common ways to originate arrays — that is, to make an array out of scalar values:

[val1, val2, val3, ...]

The most primitive way to build an array is to enumerate the successive elements of the array in square brackets. The length of the array is the number of values in the list. An exceptional case is [], which is called “nil”. A Yorick variable has the value nil before it has been defined, and [] is a way to write this special value.

array(value, dimlist)

Use array to “broadcast” (see Broadcasting) a value into an array, increasing its number of dimensions. A dimlist is a standard list of arguments used by several Yorick functions (see Dimension Lists). Often, the pseudo-index range function (see Pseudo-Index) is a clearer alternative to the array function.

span(start, stop, number)

Use span to generate a list of equally spaced values.

indgen(n)
indgen(lower:upper)
indgen(start:stop:step)

Use indgen (“index generator”) instead of span to generate equally spaced integer values. By default, the list starts with 1.

spanl(start, stop, number)

Use spanl (“span logarithmically”) to generate a list of numbers which increase or decrease by a constant ratio.


Back: 2. Using Array Syntax Forward: 2.2 Interpolating     FastBack: 2. Using Array Syntax Up: 2. Using Array Syntax FastForward: 3. Graphics         Top: Yorick: An Interpreted Language Contents: Table of Contents     About: About This Document