Some odd results returned by the Markup Expr Plus recipe.
test, if
The "test" expression evaluates arguments as a regular PmWiki condition, returning "0" or "1" accordingly.
* true: {(test expr true or false)} |
|
* false: {(test expr true and false)} |
|
* true: {(test equal "ab c" "ab c")} <= ??? |
|
* true: {(test equal "'ab c'" "'ab c'")} |
|
* true: {(test "equal 'ab c' 'ab c'")} |
|
* false: {(test equal "ab c" "ab d")} |
|
* false: {(test equal "'ab c'" "'ab d'")} |
|
* false: {(test "equal 'ab c' 'ab d'")} |
|
* false: {(test equal "ab ab" "cd ef")} <= ??? |
|
* false: {(test equal "'ab ab'" "'cd ef'")} |
|
* false: {(test "equal 'ab ab' 'cd ef'")} |
|
* true: {(test equal abc abc)} |
|
* true: {(test equal "abc" "abc")} |
|
* false: {(test equal abc def)} |
|
* false: {(test equal "abc" "def")} |
|
The "if" expression outputs its 2nd or 3rd argument according to the value of the 1st one.
* {(if (test expr true and false) "Cool!" "Aaargh...")} |
|
* {(if (test expr true or false) "Cool!" "Aaargh...")} |
|
* {(if 5-5 "Cool!" "Aaargh...")} |
|
* {(if (sub 5 5) "Cool!" "Aaargh...")} |
|
* {(if (sub 6 5) "Cool!" "Aaargh...")} |
|
* {(if (test equal (add 3 5) 8) "Cool!" "Aaargh...")} |
|
* {(if (test equal (add 3 6) 8) "Cool!" "Aaargh...")} |
|
* {(if (test expr equal (add 3 5) 8 or equal (add 3 6) 8) "Cool!" "Aaargh...")} |
|
* {(if (test expr equal (add 3 5) 8 and equal (add 3 6) 8) "Cool!" "Aaargh...")} |
|
All MarkupExpressions occur before any stand-alone PageVar references:
* Value was {(set xx 41)}, and now {(setq xx (add {$xx} 1))} is {$xx}.
* Value was {(set '' '{$xx}')}, and now {(setq xx (add {$xx} 1))} is {$xx}.
|
- Value was 41, and now is 43.
- Value was 42, and now is 43.
|
testptv1: add (mul (add 4.5 1.5) (sub 4 2)) 30
testptv2: (add (mul (add 4.5 1.5) (sub 4 2)) 30)
{(set "" "{$:testptv1}")}\\
{(set "" {$:testptv1})}\\
{(set "" ({$:testptv1}))}\\
{(set "" "{$:testptv2}")}\\
{(set "" {$:testptv2})}\\
{(set "" ({$:testptv2}))}\\
{(set "" (invalid))}
|
add (mul (add 4.5 1.5) (sub 4 2)) 30 add 42 (add (mul (add 4.5 1.5) (sub 4 2)) 30) 42 ((add)) (set (invalid))
|
MarkupExpression "if" does not prevent side effects of the path not taken:
* {(if 0 true false)}
* {(if 0 true)}
* {(if 1 true)}
* {(if 0 (set a1 "This is a1"))}
* {(if 1 (set a2 "This is a2"))}
* a1 = "{$a1}", a2 = "{$a2}".
| - false
-
- true
-
- This is a2
- a1 = "This is a1", a2 = "This is a2".
|
a1 was set. All the (if 0 ... ) did was prevent us from seeing it.
Possible work-arounds:
* {(set (if 0 b1) "This is b1")}
* {(set (if 1 b2) "This is b2")}
* b1 = "{$b1}", b2 = "{$b2}".
| - This is b1
- This is b2
- b1 = "", b2 = "This is b2".
|
* {(set c1 "c1 is "(if 0 "really true" "really false"))}
* {(set c2 "c2 is "(if 1 "really true" "really false"))}
* c1 = "{$c1}", c2 = "{$c2}".
| - c1 is really false
- c2 is really true
- c1 = "c1 is really false", c2 = "c2 is really true".
|
(if ... ) fails if false argument is 0:
* {(if 0 true false)}
* {(if 0 true 0)}
|
|