Check-in [686a2667f2]

Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Work around a bug in the fossil markdown renderer
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:686a2667f2c6835392931e0d87a6a4ad6966fde76457739a26580ef896ad7877
User & Date: dkf 2019-04-14 16:12:56
Context
2019-04-15
12:22
Editorial tweaking of 538 check-in: 11e42c47e0 user: dkf tags: trunk
2019-04-14
16:12
Work around a bug in the fossil markdown renderer check-in: 686a2667f2 user: dkf tags: trunk
16:07
Regenerate the index check-in: 51c5eaa0b1 user: dkf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to tip/539.md.

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100


101
102
103
104
105
106
107
...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
to, e.g., select all three of `-foo`, `-bar`, and `-baz`. (It could select both 
`-bar` and `-baz` through the pattern `-ba[rz]`, but that's neither common nor 
particularly readable.) However, in many instances where this kind of 
pattern is used (notably **glob**, **namespace export**, and 
**switch**), it is possible to give several such patterns and have it 
interpreted as the union of the patterns. Were that the case with 
**dict filter**, the "`-foo`, `-bar`, and `-baz`" problem could be solved as 
easily as

    dict filter $opts key -foo -bar -baz

which is comparable to

    dict remove $opts -foo -bar -baz
    dict replace $opts -foo 1 -bar off -baz 42

and much nicer than the **script** counterpart

    dict filter $opts script {key val} {
        ::tcl::mathop::in $key {-foo -bar -baz}
    }

If the **key** form is generalised like this, then it seems appropriate 
to also generalise the **value** form in the same way to keep the 
symmetry, even though I have no immediate use-case for that feature.

Since it is generally good to Do Nothing Gracefully, the command syntax is
also generalised to allow the case of no patterns at all. The result in that
................................................................................
matching) but logic reversed. This would however be so close to 
**dict filter** ... **key** that extending the syntax of the latter 
seemed more appropriate.

An alternative to allowing multiple patterns with **dict filter** could 
be to allow a regular expression pattern, since the union of two regular 
languages is again a regular language. Any syntax that could be picked for 
that would however on one hand already be rather close to

    dict filter $opts script {key val} {regexp $RE $key}

and on the other it would be rather difficult to read, as the regular 
expression corresponding to "`-foo` or `-bar` or `-baz`" is

    ^(-foo|-bar|-baz)$

which it is tempting but incorrect to simplify to `-foo|-bar|-baz`.



# Implementation Notes

An implementation exists (it's a very trivial to modify **dict filter** 
… **value** to work this way: just add an inner loop over the list of 
patterns); see [patch #2370575](/tcl/tktview/2370575).

................................................................................
**dict filter** does not guarantee keys in the result to be in the same 
order as in the input dictionary.

Indeed, a **dict filter** … **key** that reorders keys according to 
its pattern arguments could sometimes be useful in interactive situations, 
as a way of getting selected keys up from in a dictionary:

    set D {-baz 0 -bar 1 -foo 2}
    dict filter $D key -foo -bar *

On the other hand, this effect can mostly be obtained through use of 
**dict merge** already:

    dict merge {-foo x -bar x} $D

# Copyright

This document has been placed in the public domain. 







|

|

|

|
|

|

|
|
|







 







|

|


|

|

|
>
>







 







|
|




|




35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
to, e.g., select all three of `-foo`, `-bar`, and `-baz`. (It could select both 
`-bar` and `-baz` through the pattern `-ba[rz]`, but that's neither common nor 
particularly readable.) However, in many instances where this kind of 
pattern is used (notably **glob**, **namespace export**, and 
**switch**), it is possible to give several such patterns and have it 
interpreted as the union of the patterns. Were that the case with 
**dict filter**, the "`-foo`, `-bar`, and `-baz`" problem could be solved as 
easily as:

      dict filter $opts key -foo -bar -baz

which is comparable to:

      dict remove $opts -foo -bar -baz
      dict replace $opts -foo 1 -bar off -baz 42

and much nicer than the **script** counterpart:

      dict filter $opts script {key val} {
          ::tcl::mathop::in $key {-foo -bar -baz}
      }

If the **key** form is generalised like this, then it seems appropriate 
to also generalise the **value** form in the same way to keep the 
symmetry, even though I have no immediate use-case for that feature.

Since it is generally good to Do Nothing Gracefully, the command syntax is
also generalised to allow the case of no patterns at all. The result in that
................................................................................
matching) but logic reversed. This would however be so close to 
**dict filter** ... **key** that extending the syntax of the latter 
seemed more appropriate.

An alternative to allowing multiple patterns with **dict filter** could 
be to allow a regular expression pattern, since the union of two regular 
languages is again a regular language. Any syntax that could be picked for 
that would however on one hand already be rather close to:

      dict filter $opts script {key val} {regexp $RE $key}

and on the other it would be rather difficult to read, as the regular 
expression corresponding to "`-foo` or `-bar` or `-baz`" is:

      ^(-foo|-bar|-baz)$

which it is tempting but incorrect to simplify to:

      -foo|-bar|-baz

# Implementation Notes

An implementation exists (it's a very trivial to modify **dict filter** 
… **value** to work this way: just add an inner loop over the list of 
patterns); see [patch #2370575](/tcl/tktview/2370575).

................................................................................
**dict filter** does not guarantee keys in the result to be in the same 
order as in the input dictionary.

Indeed, a **dict filter** … **key** that reorders keys according to 
its pattern arguments could sometimes be useful in interactive situations, 
as a way of getting selected keys up from in a dictionary:

      set D {-baz 0 -bar 1 -foo 2}
      dict filter $D key -foo -bar *

On the other hand, this effect can mostly be obtained through use of 
**dict merge** already:

      dict merge {-foo x -bar x} $D

# Copyright

This document has been placed in the public domain.