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

From Second Life Wiki
Jump to navigation Jump to search
m
Line 1: Line 1:
{{#if:
{{#vardefine:spec|{{#if:{{#var:spec}}|{{#var:spec}}<br/>}}
{{#vardefine:spec|{{#if:{{#var:spec}}|{{#var:spec}}<br/>}}
<div style="float:left">
<div style="float:left">
Line 16: Line 18:
{{!}}}
{{!}}}
</div>
</div>
Mentally first translate any negative indexes into positive indexes
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 '''{{{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''']
*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.
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.
See {{LSLGC|Negative_Index#Range Functions|negative indexes}} for more information.
}}{{#vardefine:p_{{{1|none}}}_desc|{{{1|start}}} index
}}
}}{{#vardefine:p_{{{2|none}}}_desc|{{{2|end}}} index
 
}}<noinclude>{{#var:spec}}</noinclude>
{{#vardefine:p_{{{1|start}}}_desc|{{{1|start}}} index}}
 
{{#vardefine:p_{{{2|end}}}_desc|{{{2|end}}} index}}
 
}}<noinclude>
{| {{Prettytable}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_{{{1|start}}}_desc}}
|-
{{VarPair|p_{{{1|end}}}_desc}}
|-
{{VarPair|spec}}
|}
</noinclude>

Revision as of 14:56, 17 April 2009

#var value
p_start_desc start index
p_end_desc end index
spec
Index Positive Negative
First 0 -length
Last length - 1 -1

The easiest way to work with negative indexes is to think of them in positive index form.

  • 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]

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 negative indexes for more information.