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 EnablePost = 1, keys=
 1: 00.00 00.00 config start
 2: 00.01 00.01 config end
 3: 00.03 00.03 MarkupToHTML begin
 4: 00.03 00.03 MarkupToHTML begin
 5: 00.04 00.03 MarkupToHTML end
 6: 00.04 00.03 MarkupToHTML begin
 7: 00.04 00.03 MarkupToHTML end
 8: 00.04 00.03 MarkupToHTML begin
 9: 00.04 00.04 MarkupToHTML end
10: 00.04 00.04 MarkupToHTML begin
11: 00.04 00.04 MarkupToHTML end
12: 00.04 00.04 MarkupToHTML begin
13: 00.04 00.04 MarkupToHTML end
14: 00.04 00.04 MarkupToHTML begin
15: 00.04 00.04 MarkupToHTML end
16: 00.04 00.04 MarkupToHTML begin
17: 00.04 00.04 MarkupToHTML end
18: 00.04 00.04 MarkupToHTML begin
19: 00.04 00.04 MarkupToHTML end
20: 00.04 00.04 MarkupToHTML begin
21: 00.04 00.04 MarkupToHTML end
22: 00.04 00.04 MarkupToHTML begin
23: 00.04 00.04 MarkupToHTML end
24: 00.04 00.04 MarkupToHTML begin
25: 00.04 00.04 MarkupToHTML end
26: 00.04 00.04 MarkupToHTML begin
27: 00.04 00.04 MarkupToHTML end
28: 00.04 00.04 MarkupToHTML begin
29: 00.05 00.04 MarkupToHTML end
30: 00.05 00.04 MarkupToHTML begin
31: 00.05 00.04 MarkupToHTML end
32: 00.05 00.04 MarkupToHTML begin
33: 00.05 00.04 MarkupToHTML end
34: 00.05 00.04 MarkupToHTML begin
35: 00.05 00.04 MarkupToHTML end
36: 00.05 00.04 MarkupToHTML begin
37: 00.05 00.04 MarkupToHTML end
38: 00.05 00.04 MarkupToHTML begin
39: 00.05 00.04 MarkupToHTML end
40: 00.05 00.04 MarkupToHTML begin
41: 00.05 00.04 MarkupToHTML end
42: 00.05 00.04 MarkupToHTML begin
43: 00.05 00.04 MarkupToHTML end
44: 00.05 00.04 MarkupToHTML begin
45: 00.05 00.04 MarkupToHTML end
46: 00.05 00.04 MarkupToHTML begin
47: 00.05 00.04 MarkupToHTML end
48: 00.05 00.04 MarkupToHTML begin
49: 00.05 00.04 MarkupToHTML end
50: 00.05 00.04 MarkupToHTML begin
51: 00.05 00.05 MarkupToHTML end
52: 00.05 00.05 MarkupToHTML begin
53: 00.05 00.05 MarkupToHTML end
54: 00.05 00.05 MarkupToHTML begin
55: 00.05 00.05 MarkupToHTML end
56: 00.05 00.05 MarkupToHTML begin
57: 00.05 00.05 MarkupToHTML end
58: 00.05 00.05 MarkupToHTML begin
59: 00.06 00.05 MarkupToHTML end
60: 00.06 00.05 MarkupToHTML begin
61: 00.06 00.05 MarkupToHTML end
62: 00.06 00.05 MarkupToHTML begin
63: 00.06 00.05 MarkupToHTML end
64: 00.06 00.05 MarkupToHTML begin
65: 00.06 00.05 MarkupToHTML end
66: 00.06 00.05 MarkupToHTML begin
67: 00.06 00.06 MarkupToHTML end
68: 00.08 00.07 MarkupToHTML end
69: 00.09 00.08 MarkupToHTML begin
70: 00.10 00.09 ReadApprovedUrls SiteAdmin.ApprovedUrls begin
71: 00.10 00.09 ReadApprovedUrls SiteAdmin.ApprovedUrls end
72: 00.11 00.10 MarkupToHTML end
73: 00.11 00.10 MarkupToHTML begin
74: 00.11 00.10 MarkupToHTML end
75: 00.12 00.10 now
Peak memory: 4,066,536 bytes