Sequence Operator


Evaluates «m» and «n» and returns a sequence from «m» to «n» in increments of 1. The result is a list. For example

1..5 → [1, 2, 3, 4 ,5]

It is equivalent to Sequence(m, n) when m<=n.

This function does not array abstract. The expressions, «m» and «n», must evaluate to scalars.

With dates

The operator works with dates or date-times, incrementing in one-day steps:

5-May-2023 .. 8-May-2023 → [ 5-May-2023, 6-May-2023, 7-May-2023, 8-May-2023 ]

With text

You can use it to create one-character sequences:

'a'..'f' → [ 'a', 'b', 'c', 'd', 'e', 'f' ]

Or base 26 sequences (which is useful for identifying the column names in a spreadsheet):

'XY' .. 'YD' → [ 'XY', 'XZ', 'YA', 'YB', 'YC', 'YD' ]

When m > n

Starting in Analytica 6.4, the result is the empty list (by default) when m<n.

1..0 → [ ]
5..2 → [ ]

which is the empty list. Thus, you can use this in a construct such as:

For i := 1..Size(L) Do F( Slice( L, i ) )

When L happens to be empty (size 0), this won't attempt to access slices that don't exist.

If you want a decrementing sequence when m>n, you should use Sequence( m, n ).

Legacy behavior when m > n

In Analytica 6.3 and earlier ("legacy releases") the behavior was to return a decrementing list when m>n.

1..0 → [1,0]     { deprecated legacy behavior }
5..2 → [5, 4, 3, 2]     { deprecated legacy behavior }

To provide backward compatibility so that a model prior to Analytica 6.4 computes the same when loaded into release Analytica 6.4 or later, there is a legacy model setting on the Preferences dialog named "m..n decrements when m>n". When this is set, then the legacy behavior is used, returning a decrementing list when m>n. This preference setting stores its value in the system variable Sys_DotDotSequenceIsStrict

The decrementing behavior was a common source of bugs, so we recommend that you review your legacy model code and once you verify that you aren't relying on backward decrementing behavior, turn the preference off.

It is also possible that you might a legacy module or legacy library to your non-legacy model. Your model might assume the newer behavior, but the library might rely on the decrementing behavior. Analytica 6.4 is still able to ensure backward compatibility even in this case using a mechanism in which in annotates the sequence operators in the legacy library to indicate that they are bi-directional. When you look at a definition in the library that uses a sequence operator, this annotation appears as follows:

m ⇄.. n

This construct behaves in the bi-direction fashion regardless of the legacy model preference setting. Once you can convince yourself that m<=n, or that when m>n you want the strict behavior, you can simple delete the ⇄ character.

A mirror-image backward compatibility situation occurs when your model has the legacy preference on, but you add a library that assumes the modern strict behavior. It ensured backward compatibility in the library in a similar way, but this time by annotating the operator as

m ⇉.. n

This annotation is not added if the legacy preference setting is off when you add the library to your model.

See Also


You are not allowed to post comments.