This shows you the differences between two versions of the page.
— |
harlowe:subarray [2017/10/09 20:39] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <note important>This macro is deprecated - it may be removed in a future version of Harlowe.</note> | ||
+ | **(subarray: // [[harlowe:Array|Array]], [[harlowe:Number|Number]], Number//) -> //Array//** | ||
+ | When given an [[harlowe:Array|array]], this returns a new array containing only the elements | ||
+ | whose positions are between the two [[harlowe:number|number]], inclusively. | ||
+ | |||
+ | === Example usage: === | ||
+ | |||
+ | ''%%(subarray: $a, 3, 4)%%'' is the same as ''%%$a's (a:3,4)%%'' | ||
+ | |||
+ | === Rationale: === | ||
+ | |||
+ | You can obtain subarrays of arrays without this macro, by using the ''%%'s%%'' or ''%%of%%'' syntax along | ||
+ | with an array of positions. For instance, ''%%$a's (range:4,12)%%'' obtains a subarray of $a containing | ||
+ | its 4th through 12th values. But, for compatibility with previous Harlowe versions which did not | ||
+ | feature this syntax, this macro also exists. | ||
+ | |||
+ | === Details: === | ||
+ | |||
+ | If you provide negative numbers, they will be treated as being offset from the end | ||
+ | of the array - ''%%-2%%'' will specify the ''%%2ndlast%%'' item, just as 2 will specify | ||
+ | the ''%%2nd%%'' item. | ||
+ | |||
+ | If the last number given is larger than the first (for instance, in ''%%(subarray: (a:1,2,3,4), 4, 2)%%'') | ||
+ | then the macro will still work - in that case returning (a:2,3,4) as if the numbers were in | ||
+ | the correct order. | ||
+ | |||
+ | === See also: === | ||
+ | |||
+ | [[harlowe:substring|(substring:)]], [[harlowe:rotated|(rotated:)]] |