Jump to content

User talk:AzaToth/X1

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

How it works[edit]

The main technology used is to use parameter values to expand other parameter.

  • First we try to expand else:
    {{{else}}}
  • But else should only be expanded if test is empty:
    {{{else{{{test|{{{1|}}}}}}}}}
  • If else was not expanded, we must try parameter 3, this is the same as before:
    {{{else{{{test|{{{1|}}}}}}|{{{3{{{test|{{{1|}}}}}}}}}}}}
  • Then if 3 was not expanded, we must check if there was a parameter else or 3 in the first place, we do it by try to expand the test parameter plus their eventually value:
    {{{else{{{test|{{{1|}}}}}}|{{{3{{{test|{{{1|}}}}}}|{{{test{{{test|}}}|{{{1{{{1|}}}}}}}}}}}}}}}
  • If we come this far, we can now expand the then parameter:
    {{{else{{{test|{{{1|}}}}}}|{{{3{{{test|{{{1|}}}}}}|{{{test{{{test|}}}|{{{1{{{1|}}}|{{{then|{{{2|}}}}}}}}}}}}}}}}}}}}}
  • But we have one step more to do, the so called idiot protection, if the user called if with only the parameter then, we protect from by trying to add the value of (then plus the value of test):
    {{{else{{{test|{{{1|}}}}}}|{{{3{{{test|{{{1|}}}}}}|{{{test{{{test|}}}|{{{1{{{1|}}}|{{{then{{{then{{{test|{{{1|}}}}}}|}}}|{{{2{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}

Example[edit]

If we are calling with {{if|test=X|then=Y|else=Z}}, then:

  • {{{elseX|{{{3{{{test|{{{1|}}}}}}|{{{test{{{test|}}}|{{{1{{{1|}}}|{{{then{{{then{{{test|{{{1|}}}}}}|}}}|{{{2<{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}
  • {{{elseX|{{{3X|{{{test{{{test|}}}|{{{1{{{1|}}}|{{{then{{{then{{{test|{{{1|}}}}}}|}}}|{{{2{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}
  • {{{elseX|{{{3X|{{{testX|{{{1|{{{then{{{then{{{test|{{{1|}}}}}}|}}}|{{{2{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}
  • {{{elseX|{{{3X|{{{testX|{{{1|{{{then{{{thenX|}}}|{{{2{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}
  • {{{elseX|{{{3X|{{{testX|{{{1|{{{then|{{{2{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}
  • {{{then}}}

Tests[edit]

User:AzaToth/X1
{{{else{{{test|{{{1|}}}}}}|{{{3{{{test|{{{1|}}}}}}|{{{test{{{test|}}}|{{{1{{{1|}}}|{{{then{{{then{{{test|{{{1|}}}}}}|}}}|{{{2{{{2{{{test|{{{1|}}}}}}|}}}|}}}}}}}}}}}}}}}}}}
Template:If
{{show1|1={{{2|{{{then|}}}}}}|1{{{1|{{{test|}}}}}}={{{3|{{{else|}}}}}}}}
# Code Expected
Result
Result of
Template:if
Result of
User:AzaToth/X1
1
{{if
  |test=foo
  |then=true
  |else=false
}}
true 1|2}}|{{{3}}}|}}
2
{{if
  |test=
  |then=true
  |else=false
}}
false 1|2}}|{{{3}}}|}}
3
{{if
  |test=[]
  |then=true
  |else=false
}}
true 1|2}}|{{{3}}}|}}
4
{{if
  |then=true
  |else=false
}}
false 1|2}}|{{{3}}}|}}
5
{{if
  |test=()
  |then=true
  |else=false
}}
true 1|2}}|{{{3}}}|}}
6
{{if
  |()
  |true
  |false
}}
true {{ safesubst:p{{ safesubst:#if()
 :true
2}}|false

} |

|- |7

|

{{if
  |
  |true
  |false
}}

|false |{{ safesubst:p{{ safesubst:#if

 :true
 |1|2}}|false

|}}

|

|- |8

|

{{if
  |2=true
  |3=false
}}

|false |{{ safesubst:p{{ safesubst:#if{{{1}}}:true|1|2}}|false|}}

|

|- |9

|

{{if
  |test={{{1|}}}
  |then=true
  |else=false
}}

|false |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |10

|

{{if
  |test=""
  |then=true
  |else=false
}}

|true |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |11

|

{{if
  |test=""
  |then=true
}}

|true |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |12

|

{{if
  |test=
  |then=true
}}

| |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |13

|

{{if
  |test=
  |else=false
}}

|false |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |14

|

{{if
  |test=foo
  |then=true
}}

|true |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |15

|

{{if
  |1=
  |2=true
}}

| |{{{3}}}

|

|- |16

|

{{if
  |1=
  |3=false
}}

|false |false

|

|- |17

|

{{if
  |1=foo
  |2=true
}}

|true |{{ safesubst:p{{ safesubst:#iffoo:true|1|2}}|{{{3}}}|}}

|

|- |18

|

{{if
  |test=foo
  |else=false
}}

| |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |18

|

{{if
  |1=foo
  |3=false
}}

| |{{ safesubst:p{{ safesubst:#iffoo:{{{2}}}|1|2}}|false|}}

|

|- |19

|

{{if
  |3=false
}}

|false |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|false|}}

|

|- |20

|

{{if
  |else=false
}}

|false |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|- |21

|

{{if
  |2=true
}}

| |{{ safesubst:p{{ safesubst:#if{{{1}}}:true|1|2}}|{{{3}}}|}}

|

|- |22

|

{{if
  |then=true
}}

| |{{ safesubst:p{{ safesubst:#if{{{1}}}:{{{2}}}|1|2}}|{{{3}}}|}}

|

|}

Discussion[edit]

The only time my fails, is when you only have the parameter then or 2, but thats a not so common situation (in strict speaking, never print anything). AzaToth 01:43, 27 November 2005 (UTC) Fixed that problem by appending {{{then/2{{{test|{{{1|}}}}}}|}}} to then and 2' AzaToth 15:02, 27 November 2005 (UTC)[reply]