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: 00.00 00.00 config start
 1: 00.01 00.01 config end
 2: 00.21 00.20 MarkupToHTML begin
 3: 00.21 00.20 MarkupToHTML begin
 4: 00.21 00.21 MarkupToHTML end
 5: 00.21 00.21 MarkupToHTML begin
 6: 00.21 00.21 MarkupToHTML end
 7: 00.21 00.21 MarkupToHTML begin
 8: 00.21 00.21 MarkupToHTML end
 9: 00.21 00.21 MarkupToHTML begin
10: 00.21 00.21 MarkupToHTML end
11: 00.21 00.21 MarkupToHTML begin
12: 00.22 00.21 MarkupToHTML end
13: 00.22 00.21 MarkupToHTML begin
14: 00.22 00.21 MarkupToHTML end
15: 00.22 00.21 MarkupToHTML begin
16: 00.22 00.21 MarkupToHTML end
17: 00.22 00.21 MarkupToHTML begin
18: 00.22 00.21 MarkupToHTML end
19: 00.22 00.21 MarkupToHTML begin
20: 00.22 00.21 MarkupToHTML end
21: 00.22 00.21 MarkupToHTML begin
22: 00.22 00.21 MarkupToHTML end
23: 00.22 00.21 MarkupToHTML begin
24: 00.22 00.21 MarkupToHTML end
25: 00.22 00.21 MarkupToHTML begin
26: 00.22 00.21 MarkupToHTML end
27: 00.22 00.21 MarkupToHTML begin
28: 00.22 00.21 MarkupToHTML end
29: 00.22 00.21 MarkupToHTML begin
30: 00.22 00.22 MarkupToHTML end
31: 00.22 00.22 MarkupToHTML begin
32: 00.22 00.22 MarkupToHTML end
33: 00.22 00.22 MarkupToHTML begin
34: 00.22 00.22 MarkupToHTML end
35: 00.22 00.22 MarkupToHTML begin
36: 00.22 00.22 MarkupToHTML end
37: 00.22 00.22 MarkupToHTML begin
38: 00.22 00.22 MarkupToHTML end
39: 00.22 00.22 MarkupToHTML begin
40: 00.22 00.22 MarkupToHTML end
41: 00.22 00.22 MarkupToHTML begin
42: 00.22 00.22 MarkupToHTML end
43: 00.22 00.22 MarkupToHTML begin
44: 00.22 00.22 MarkupToHTML end
45: 00.22 00.22 MarkupToHTML begin
46: 00.22 00.22 MarkupToHTML end
47: 00.22 00.22 MarkupToHTML begin
48: 00.22 00.22 MarkupToHTML end
49: 00.22 00.22 MarkupToHTML begin
50: 00.22 00.22 MarkupToHTML end
51: 00.22 00.22 MarkupToHTML begin
52: 00.22 00.22 MarkupToHTML end
53: 00.22 00.22 MarkupToHTML begin
54: 00.23 00.22 MarkupToHTML end
55: 00.23 00.22 MarkupToHTML begin
56: 00.23 00.22 MarkupToHTML end
57: 00.23 00.22 MarkupToHTML begin
58: 00.23 00.23 MarkupToHTML end
59: 00.23 00.23 MarkupToHTML begin
60: 00.23 00.23 MarkupToHTML end
61: 00.23 00.23 MarkupToHTML begin
62: 00.23 00.23 MarkupToHTML end
63: 00.23 00.23 MarkupToHTML begin
64: 00.23 00.23 MarkupToHTML end
65: 00.23 00.23 MarkupToHTML begin
66: 00.23 00.23 MarkupToHTML end
67: 00.25 00.24 MarkupToHTML end
68: 00.25 00.25 MarkupToHTML begin
69: 00.26 00.25 ReadApprovedUrls SiteAdmin.ApprovedUrls begin
70: 00.26 00.26 ReadApprovedUrls SiteAdmin.ApprovedUrls end
71: 00.27 00.26 MarkupToHTML end
72: 00.27 00.26 MarkupToHTML begin
73: 00.27 00.27 MarkupToHTML end
74: 00.27 00.27 now
Peak memory: 3,829,752 bytes