Difference between revisions of "Template:LSL Function/negative index"
Jump to navigation
Jump to search
m |
(radical overhaul and modernization (omg you can read the code and it makes sense)) |
||
Line 6: | Line 6: | ||
{{#vardefine:also_articles|{{LSL DefineRow||Test}}}} | {{#vardefine:also_articles|{{LSL DefineRow||Test}}}} | ||
{{#vardefine:ni_mode|true}} | {{#vardefine:ni_mode|true}} | ||
{{#vardefine:ni_nc|}} | |||
{{#vardefine:ni_p1|number}} | {{#vardefine:ni_p1|number}} | ||
{{#vardefine:ni_p2|p2}} | {{#vardefine:ni_p2|p2}} | ||
Line 12: | Line 13: | ||
</noinclude>{{#if: | </noinclude>{{#if: | ||
{{#vardefine: | {{#vardefine:ni_c|{{#if:{{{2|{{#var:ni_p1}}}}}|{{#if:{{{3|{{#var:ni_p2}}}}}|{{#if:{{{4|{{#var:ni_p3}}}}}|3|2}}|1}}|0}}}} | ||
{{#vardefine:t|{{#ifeq:{{{1|{{#var:ni_mode}}}}}|true|{{#switch:{{#var:ni_c}}|3|2=LSL_Function/negative_index/range|1=LSL_Function/negative_index/single}}}}}} | |||
{{{{#var:t}}|{{{2|{{#var:ni_p1}}}}}|{{{3|{{#var:ni_p2}}}}}|{{{4|{{#var:ni_p3}}}}}}} | {{{{#var:t}}|{{{2|{{#var:ni_p1}}}}}|{{{3|{{#var:ni_p2}}}}}|{{{4|{{#var:ni_p3}}}}}}} | ||
Line 45: | Line 48: | ||
{{#if:{{#var:t}}|{{LSL_DefineRow||{{LSLGC|Negative_Index{{#var:lang}}|Negative Index}}|}}}}}} | {{#if:{{#var:t}}|{{LSL_DefineRow||{{LSLGC|Negative_Index{{#var:lang}}|Negative Index}}|}}}}}} | ||
{{#vardefine:header_footnote | {{#vardefine:header_footnote|{{#var:header_footnote}} | ||
<div>{{#switch:{{#var:ni_c}} | |||
|0=This function | |||
|1='''{{{2}}}''' | |||
|2='''{{{2}}}''' & '''{{{3}}}''' | |||
|3='''{{{2}}}''', '''{{{3}}}''' & '''{{{4}}}''' | |||
}} {{#if:{{#var:t}}| support{{#ifexpr:{{#var:ni_c}}>1||s}}| ''do{{#ifexpr:{{#var:ni_c}}>1||es}} not'' support }} {{LSLGC|Negative_Index{{#var:lang}}|negative indexes}}.</div> | |||
}} | |||
{{#vardefine:footer|{{#var:footer}} | {{#vardefine:footer|{{#var:footer}} | ||
{{#if:{{#var:t}}|{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{#var:self}}{{{self|}}}||{{LSLC|Negative Index{{#var:lang}}}}}}}}}}}} | {{#if:{{#var:t}}|{{#ifeq:{{NAMESPACE}}|Template||{{#if:{{#var:self}}{{{self|}}}||{{LSLC|Negative Index{{#var:lang}}}}}}}}}}}} | ||
{{#vardefine:caveats|{{#var:caveats}} | |||
{{#if:{{{nc|{{#var:ni_nc}}}}}|| | |||
* If {{#switch:{{#var:ni_c}} | |||
|3=either '''{{{2}}}''', '''{{{3}}}''' or '''{{{4}}}''' are | |||
|2=either '''{{{2}}}''' or '''{{{3}}}''' are | |||
|1='''{{{2}}}'''is}} out of bounds the script continues to execute without an error message. | |||
}}}} | |||
}}<noinclude> | }}<noinclude> |
Revision as of 17:53, 17 April 2009
Format:
{{LSL Function/negative index|boolean|p1|p2|p3}}
Exclude p1, p2, or p3 if not used.
Debugging
#var | value | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
header_footnote | {{{2}}} & {{{3}}} support negative indexes.
| ||||||||||
spec |
Indexes
| ||||||||||
caveats |
| ||||||||||
notes |
Ranges & IndexesThe 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.
See negative indexes for more information. | ||||||||||
constants_nb | |||||||||||
also_articles |
| ||||||||||
footer |