MarkupExprPlusAnomalies

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 true)}
  • true: 1
* false: {(test false)}
  • false: 0
* true: {(test expr true or false)}
  • true: 1
* false: {(test expr true and false)}
  • false: 0
* true: {(test equal "ab c" "ab c")} <= ???
  • true: 1 <= ???
* true: {(test equal "'ab c'" "'ab c'")}
  • true: 1
* true: {(test "equal 'ab c' 'ab c'")}
  • true: 1
* false: {(test equal "ab c" "ab d")}
  • false: 0
* false: {(test equal "'ab c'" "'ab d'")}
  • false: 0
* false: {(test "equal 'ab c' 'ab d'")}
  • false: 1
* false: {(test equal "ab ab" "cd ef")} <= ???
  • false: 0 <= ???
* false: {(test equal "'ab ab'" "'cd ef'")}
  • false: 0
* false: {(test "equal 'ab ab' 'cd ef'")}
  • false: 1
* true: {(test equal abc abc)}
  • true: 1
* true: {(test equal "abc" "abc")}
  • true: 1
* false: {(test equal abc def)}
  • false: 0
* false: {(test equal "abc" "def")}
  • false: 0

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...")}
  • Aaargh...
* {(if (test expr true or false) "Cool!" "Aaargh...")}
  • Cool!
* {(if 5-5 "Cool!" "Aaargh...")}
  • Cool!
* {(if (sub 5 5) "Cool!" "Aaargh...")}
  • Aaargh...
* {(if (sub 6 5) "Cool!" "Aaargh...")}
  • Cool!
* {(if (test equal (add 3 5) 8) "Cool!" "Aaargh...")}
  • Cool!
* {(if (test equal (add 3 6) 8) "Cool!" "Aaargh...")}
  • Aaargh...
* {(if (test expr equal (add 3 5) 8 or equal (add 3 6) 8) "Cool!" "Aaargh...")}
  • Cool!
* {(if (test expr equal (add 3 5) 8 and equal (add 3 6) 8) "Cool!" "Aaargh...")}
  • 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)}
  • false
  • 0
Peak memory: 1,534,224 bytes