Difference between revisions of "Template:LSL Function/negative index/range"

From Second Life Wiki
Jump to navigation Jump to search
m (Undo revision 323193 by Strife Onizuka (Talk) i thought it worked but it didn't)
m (typo correction. "Then" vs "Than".)
 
(13 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{#if:
{{#if:


{{#vardefine:spec|{{#if:{{#var:spec}}|{{#var:spec}}<br/>}}
TODO: --FIXME--
<div style="float:left">
* Figure out how to support {{{noExclude|}}} for llListListStride.
{{{!}}{{Prettytable}}
{{!}}-{{Hl2}}
! Index
! Positive
! Negative
{{!}}-
{{!}} First
{{!}} 0
{{!}} -length
{{!}}-
{{!}} Last
{{!}} length - 1
{{!}} -1
{{!}}}
</div>
The easiest way to work with negative indexes is to think of them in positive index form.
<div style="display: table;">
*If '''{{{1}}}''' <= '''{{{2}}}''' then the range operated on starts at '''{{{1}}}''' and ends at '''{{{2}}}'''. ['''{{{1}}}''', '''{{{2}}}''']
*If '''{{{1}}}''' > '''{{{2}}}''' then the range operated on starts at '''0''' and goes to '''{{{2}}}''' and then starts again at '''{{{1}}}''' and goes to '''-1'''. ['''0''', '''{{{2}}}'''] + ['''{{{1}}}''', '''-1''']
</div>
Positive indexes past the length (after the last index), or negative indexes past the beginning (before the first index) are valid. The effects are predictable, the entries are treated as if they were there but were removed just before output.
 
See {{LSLGC|Negative_Index#Range Functions|negative indexes}} for more information.
}}


{{#vardefine:p_{{{1|start}}}_desc|{{{1|start}}} index}}
{{#vardefine:p_{{{1|start}}}_desc|{{{1|start}}} index}}


{{#vardefine:p_{{{2|end}}}_desc|{{{2|end}}} index}}
{{#vardefine:p_{{{2|end}}}_desc|{{{2|end}}} index}}
{{#vardefine:notes|{{#var:notes}}{{PBR}}
=== Ranges & Indexes ===
The easiest way to explain how ranges work is to make all indexes positive. Negative indexes are just a way of counting from the tail end instead of the beginning, all negative indexes have a corresponding equivalent positive index (assuming they are in range). Positive indexes past length (after the last index), or negative indexes past the beginning (before the first index) are valid and the effects are predictable and reliable: the entries are treated as if they were there but were removed just before output.
*If {{LSLP|{{{1}}}}} <= {{LSLP|{{{2}}}}} then the range operated on starts at {{LSLP|{{{1}}}}} and ends at {{LSLP|{{{2}}}}}. [{{LSLP|{{{1}}}}}, {{LSLP|{{{2}}}}}]
*<span id="exclusion_range">Exclusion range</span>: If {{LSLP|{{{1}}}}} > {{LSLP|{{{2}}}}} then the range operated on starts at {{LSLP|0}} and goes to {{LSLP|{{{2}}}}} and then starts again at {{LSLP|{{{1}}}}} and goes to {{LSLP|-1}}. [{{LSLP|0}}, {{LSLP|{{{2}}}}}] + [{{LSLP|{{{1}}}}}, {{LSLP|-1}}]
**If {{LSLP|{{{2}}}}} is a negative index past the beginning, then the operating range would be [{{LSLP|{{{1}}}}}, {{LSLP|-1}}].
**If {{LSLP|{{{2}}}}} is a positive index past the end, then the operating range would be [{{LSLP|0}}, {{LSLP|{{{2}}}}}].
**If both {{LSLP|{{{1}}}}} and {{LSLP|{{{2}}}}} are out of bounds then the function would have no operating range (effectively inverting what the function is supposed to do).
See {{LSLGC|Negative_Index#Range Functions|negative indexes}} for more information.
}}


}}<noinclude>
}}<noinclude>
Line 43: Line 32:
|-
|-
{{VarPair|spec}}
{{VarPair|spec}}
|-
{{VarPair|notes}}
|-
{{VarPair|caveats}}
|}
|}
</noinclude>
</noinclude>

Latest revision as of 10:37, 28 December 2020

#var value
p_start_desc start index
p_end_desc end index
spec
notes

Ranges & Indexes

The easiest way to explain how ranges work is to make all indexes positive. Negative indexes are just a way of counting from the tail end instead of the beginning, all negative indexes have a corresponding equivalent positive index (assuming they are in range). Positive indexes past length (after the last index), or negative indexes past the beginning (before the first index) are valid and the effects are predictable and reliable: the entries are treated as if they were there but were removed just before output.

  • If {{{1}}} <= {{{2}}} then the range operated on starts at {{{1}}} and ends at {{{2}}}. [{{{1}}}, {{{2}}}]
  • Exclusion range: If {{{1}}} > {{{2}}} then the range operated on starts at 0 and goes to {{{2}}} and then starts again at {{{1}}} and goes to -1. [0, {{{2}}}] + [{{{1}}}, -1]
    • If {{{2}}} is a negative index past the beginning, then the operating range would be [{{{1}}}, -1].
    • If {{{2}}} is a positive index past the end, then the operating range would be [0, {{{2}}}].
    • If both {{{1}}} and {{{2}}} are out of bounds then the function would have no operating range (effectively inverting what the function is supposed to do).

See negative indexes for more information.

caveats