Skip to content

Commit 97644e9

Browse files
struct::list - EF - equal extended with new option -simple.
Version bumped to 1.9. struct::set - B - Fix mishandling of method shorthands in the Tcl implementation. Version bumped to 2.2.5 Thanks to Emiliano for the patch providing most of the fix.
1 parent 11f931e commit 97644e9

File tree

15 files changed

+123
-96
lines changed

15 files changed

+123
-96
lines changed

embedded/md/tcllib/files/modules/struct/struct_list.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[//000000002]: # (Generated from file 'struct\_list\.man' by tcllib/doctools with format 'markdown')
44
[//000000003]: # (Copyright © 2003\-2005 by Kevin B\. Kenny\. All rights reserved)
55
[//000000004]: # (Copyright &copy; 2003\-2012 Andreas Kupries <andreas\_kupries@users\.sourceforge\.net>)
6-
[//000000005]: # (struct::list\(n\) 1\.8\.6 tcllib "Tcl Data Structures")
6+
[//000000005]: # (struct::list\(n\) 1\.9 tcllib "Tcl Data Structures")
77

88
<hr> [ <a href="../../../../toc.md">Main Table Of Contents</a> &#124; <a
99
href="../../../toc.md">Table Of Contents</a> &#124; <a
@@ -43,7 +43,7 @@ struct::list \- Procedures for manipulating lists
4343
# <a name='synopsis'></a>SYNOPSIS
4444

4545
package require Tcl 8\.5 9
46-
package require struct::list ?1\.8\.6?
46+
package require struct::list ?1\.9?
4747

4848
[__::struct::list__ __longestCommonSubsequence__ *sequence1* *sequence2* ?*maxOccurs*?](#1)
4949
[__::struct::list__ __longestCommonSubsequence2__ *sequence1 sequence2* ?*maxOccurs*?](#2)
@@ -63,7 +63,7 @@ package require struct::list ?1\.8\.6?
6363
[__::struct::list__ __fold__ *sequence* *initialvalue* *cmdprefix*](#16)
6464
[__::struct::list__ __shift__ *listvar*](#17)
6565
[__::struct::list__ __iota__ *n*](#18)
66-
[__::struct::list__ __equal__ *a* *b*](#19)
66+
[__::struct::list__ __equal__ ?__\-simple__? ?__\-\-__? *a* *b*](#19)
6767
[__::struct::list__ __repeat__ *size* *element1* ?*element2* *element3*\.\.\.?](#20)
6868
[__::struct::list__ __repeatn__ *value* *size*\.\.\.](#21)
6969
[__::struct::list__ __dbJoin__ ?__\-inner__&#124;__\-left__&#124;__\-right__&#124;__\-full__? ?__\-keys__ *varname*? \{*keycol* *table*\}\.\.\.](#22)
@@ -419,12 +419,18 @@ provided here can be reached through a subcommand of this command\.
419419

420420
For "*n* == __0__" an empty list will be returned\.
421421

422-
- <a name='19'></a>__::struct::list__ __equal__ *a* *b*
422+
- <a name='19'></a>__::struct::list__ __equal__ ?__\-simple__? ?__\-\-__? *a* *b*
423423

424424
The subcommand compares the two lists *a* and *b* for equality\. In other
425425
words, they have to be of the same length and have to contain the same
426-
elements in the same order\. If an element is a list the same definition of
427-
equality applies recursively\.
426+
elements in the same order\.
427+
428+
By default equality checks are applied recursively to list elements which
429+
are lists themselves\. This behaviour is disabled when specifying the option
430+
__\-simple__\.
431+
432+
The option __\-\-__ disables option processing even if the following
433+
argument looks like such\.
428434

429435
A boolean value will be returned as the result of the command\. This value
430436
will be __true__ if the two lists are equal, and __false__ else\.

embedded/md/tcllib/files/modules/struct/struct_set.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[//000000001]: # (struct::set \- Tcl Data Structures)
33
[//000000002]: # (Generated from file 'struct\_set\.man' by tcllib/doctools with format 'markdown')
44
[//000000003]: # (Copyright &copy; 2004\-2008 Andreas Kupries <andreas\_kupries@users\.sourceforge\.net>)
5-
[//000000004]: # (struct::set\(n\) 2\.2\.4 tcllib "Tcl Data Structures")
5+
[//000000004]: # (struct::set\(n\) 2\.2\.5 tcllib "Tcl Data Structures")
66

77
<hr> [ <a href="../../../../toc.md">Main Table Of Contents</a> &#124; <a
88
href="../../../toc.md">Table Of Contents</a> &#124; <a

idoc/man/files/modules/struct/struct_list.n

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'\" Copyright (c) 2003-2005 by Kevin B\&. Kenny\&. All rights reserved
44
'\" Copyright (c) 2003-2012 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
55
'\"
6-
.TH "struct::list" n 1\&.8\&.6 tcllib "Tcl Data Structures"
6+
.TH "struct::list" n 1\&.9 tcllib "Tcl Data Structures"
77
.\" The -*- nroff -*- definitions below are for supplemental macros used
88
.\" in Tcl/Tk manual entries.
99
.\"
@@ -277,7 +277,7 @@ struct::list \- Procedures for manipulating lists
277277
.SH SYNOPSIS
278278
package require \fBTcl 8\&.5 9\fR
279279
.sp
280-
package require \fBstruct::list ?1\&.8\&.6?\fR
280+
package require \fBstruct::list ?1\&.9?\fR
281281
.sp
282282
\fB::struct::list\fR \fBlongestCommonSubsequence\fR \fIsequence1\fR \fIsequence2\fR ?\fImaxOccurs\fR?
283283
.sp
@@ -315,7 +315,7 @@ package require \fBstruct::list ?1\&.8\&.6?\fR
315315
.sp
316316
\fB::struct::list\fR \fBiota\fR \fIn\fR
317317
.sp
318-
\fB::struct::list\fR \fBequal\fR \fIa\fR \fIb\fR
318+
\fB::struct::list\fR \fBequal\fR ?\fB-simple\fR? ?\fB--\fR? \fIa\fR \fIb\fR
319319
.sp
320320
\fB::struct::list\fR \fBrepeat\fR \fIsize\fR \fIelement1\fR ?\fIelement2\fR \fIelement3\fR\&.\&.\&.?
321321
.sp
@@ -723,11 +723,15 @@ of the list contain the number \fBi\fR\&.
723723
.sp
724724
For "\fIn\fR == \fB0\fR" an empty list will be returned\&.
725725
.TP
726-
\fB::struct::list\fR \fBequal\fR \fIa\fR \fIb\fR
726+
\fB::struct::list\fR \fBequal\fR ?\fB-simple\fR? ?\fB--\fR? \fIa\fR \fIb\fR
727727
The subcommand compares the two lists \fIa\fR and \fIb\fR for
728728
equality\&. In other words, they have to be of the same length and have
729-
to contain the same elements in the same order\&. If an element is a
730-
list the same definition of equality applies recursively\&.
729+
to contain the same elements in the same order\&.
730+
.sp
731+
By default equality checks are applied recursively to list elements which are lists themselves\&.
732+
This behaviour is disabled when specifying the option \fB-simple\fR\&.
733+
.sp
734+
The option \fB--\fR disables option processing even if the following argument looks like such\&.
731735
.sp
732736
A boolean value will be returned as the result of the command\&.
733737
This value will be \fBtrue\fR if the two lists are equal, and

idoc/man/files/modules/struct/struct_set.n

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'\" Generated from file 'struct_set\&.man' by tcllib/doctools with format 'nroff'
33
'\" Copyright (c) 2004-2008 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
44
'\"
5-
.TH "struct::set" n 2\&.2\&.4 tcllib "Tcl Data Structures"
5+
.TH "struct::set" n 2\&.2\&.5 tcllib "Tcl Data Structures"
66
.\" The -*- nroff -*- definitions below are for supplemental macros used
77
.\" in Tcl/Tk manual entries.
88
.\"

idoc/www/tcllib/files/modules/struct/struct_list.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
&#124; <a href="../../../../toc2.html">Applications</a>
110110
] <hr>
111111
<div class="doctools">
112-
<h1 class="doctools_title">struct::list(n) 1.8.6 tcllib &quot;Tcl Data Structures&quot;</h1>
112+
<h1 class="doctools_title">struct::list(n) 1.9 tcllib &quot;Tcl Data Structures&quot;</h1>
113113
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
114114
<p>struct::list - Procedures for manipulating lists</p>
115115
</div>
@@ -132,7 +132,7 @@ <h1 class="doctools_title">struct::list(n) 1.8.6 tcllib &quot;Tcl Data Structure
132132
<div class="doctools_synopsis">
133133
<ul class="doctools_requirements">
134134
<li>package require <b class="pkgname">Tcl 8.5 9</b></li>
135-
<li>package require <b class="pkgname">struct::list <span class="opt">?1.8.6?</span></b></li>
135+
<li>package require <b class="pkgname">struct::list <span class="opt">?1.9?</span></b></li>
136136
</ul>
137137
<ul class="doctools_syntax">
138138
<li><a href="#1"><b class="cmd">::struct::list</b> <b class="method">longestCommonSubsequence</b> <i class="arg">sequence1</i> <i class="arg">sequence2</i> <span class="opt">?<i class="arg">maxOccurs</i>?</span></a></li>
@@ -153,7 +153,7 @@ <h1 class="doctools_title">struct::list(n) 1.8.6 tcllib &quot;Tcl Data Structure
153153
<li><a href="#16"><b class="cmd">::struct::list</b> <b class="method">fold</b> <i class="arg">sequence</i> <i class="arg">initialvalue</i> <i class="arg">cmdprefix</i></a></li>
154154
<li><a href="#17"><b class="cmd">::struct::list</b> <b class="method">shift</b> <i class="arg">listvar</i></a></li>
155155
<li><a href="#18"><b class="cmd">::struct::list</b> <b class="method">iota</b> <i class="arg">n</i></a></li>
156-
<li><a href="#19"><b class="cmd">::struct::list</b> <b class="method">equal</b> <i class="arg">a</i> <i class="arg">b</i></a></li>
156+
<li><a href="#19"><b class="cmd">::struct::list</b> <b class="method">equal</b> <span class="opt">?<b class="option">-simple</b>?</span> <span class="opt">?<b class="option">--</b>?</span> <i class="arg">a</i> <i class="arg">b</i></a></li>
157157
<li><a href="#20"><b class="cmd">::struct::list</b> <b class="method">repeat</b> <i class="arg">size</i> <i class="arg">element1</i> <span class="opt">?<i class="arg">element2</i> <i class="arg">element3</i>...?</span></a></li>
158158
<li><a href="#21"><b class="cmd">::struct::list</b> <b class="method">repeatn</b> <i class="arg">value</i> <i class="arg">size</i>...</a></li>
159159
<li><a href="#22"><b class="cmd">::struct::list</b> <b class="method">dbJoin</b> <span class="opt">?<b class="option">-inner</b>|<b class="option">-left</b>|<b class="option">-right</b>|<b class="option">-full</b>?</span> <span class="opt">?<b class="option">-keys</b> <i class="arg">varname</i>?</span> {<i class="arg">keycol</i> <i class="arg">table</i>}...</a></li>
@@ -468,11 +468,13 @@ <h1 class="doctools_title">struct::list(n) 1.8.6 tcllib &quot;Tcl Data Structure
468468
in the range <b class="const">[0,n)</b>. The element at index <b class="variable">i</b>
469469
of the list contain the number <b class="const">i</b>.</p>
470470
<p>For &quot;<i class="arg">n</i> == <b class="const">0</b>&quot; an empty list will be returned.</p></dd>
471-
<dt><a name="19"><b class="cmd">::struct::list</b> <b class="method">equal</b> <i class="arg">a</i> <i class="arg">b</i></a></dt>
471+
<dt><a name="19"><b class="cmd">::struct::list</b> <b class="method">equal</b> <span class="opt">?<b class="option">-simple</b>?</span> <span class="opt">?<b class="option">--</b>?</span> <i class="arg">a</i> <i class="arg">b</i></a></dt>
472472
<dd><p>The subcommand compares the two lists <i class="arg">a</i> and <i class="arg">b</i> for
473473
equality. In other words, they have to be of the same length and have
474-
to contain the same elements in the same order. If an element is a
475-
list the same definition of equality applies recursively.</p>
474+
to contain the same elements in the same order.</p>
475+
<p>By default equality checks are applied recursively to list elements which are lists themselves.
476+
This behaviour is disabled when specifying the option <b class="option">-simple</b>.</p>
477+
<p>The option <b class="option">--</b> disables option processing even if the following argument looks like such.</p>
476478
<p>A boolean value will be returned as the result of the command.
477479
This value will be <b class="const">true</b> if the two lists are equal, and
478480
<b class="const">false</b> else.</p></dd>

idoc/www/tcllib/files/modules/struct/struct_set.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
&#124; <a href="../../../../toc2.html">Applications</a>
110110
] <hr>
111111
<div class="doctools">
112-
<h1 class="doctools_title">struct::set(n) 2.2.4 tcllib &quot;Tcl Data Structures&quot;</h1>
112+
<h1 class="doctools_title">struct::set(n) 2.2.5 tcllib &quot;Tcl Data Structures&quot;</h1>
113113
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
114114
<p>struct::set - Procedures for manipulating sets</p>
115115
</div>

modules/struct/list.tcl

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# See the file "license.terms" for information on usage and redistribution
1010
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1111
#
12-
# RCS: @(#) $Id: list.tcl,v 1.27 2011/09/17 14:35:36 mic42 Exp $
13-
#
1412
#----------------------------------------------------------------------
1513

1614
package require Tcl 8.5 9
@@ -944,12 +942,39 @@ proc ::struct::list::Ldelete {var item} {
944942
# Side effects:
945943
# None
946944

947-
proc ::struct::list::Lequal {a b} {
945+
proc ::struct::list::Lequal {a b args} {
946+
# Author of this command is "Richard Suchenwirth"
947+
948+
set args [::lreverse [::lassign [::lreverse [::list $a $b {*}$args]] a b]]
949+
# a b args --> args a b
950+
set recurse 1
951+
while {[string match -* [set o [::lindex $args 0]]]} {
952+
set args [::lrange $args 1 end]
953+
switch -exact -- $o {
954+
-- break
955+
-simple { set recurse 0 }
956+
default {
957+
return -code error "Bad option \"$o\", expected -simple, or --"
958+
}
959+
}
960+
}
961+
if {[::llength $args]} {
962+
return -code error "too many arguments after options"
963+
}
964+
return [EqualCore $recurse $a $b]
965+
}
966+
967+
proc ::struct::list::EqualCore {recurse a b} {
948968
# Author of this command is "Richard Suchenwirth"
949969

950970
if {[::llength $a] != [::llength $b]} {return 0}
951971
if {[::lindex $a 0] == $a && [::lindex $b 0] == $b} {return [string equal $a $b]}
952-
foreach i $a j $b {if {![Lequal $i $j]} {return 0}}
972+
973+
if {$recurse} {
974+
foreach i $a j $b {if {![EqualCore $recurse $i $j]} {return 0}}
975+
} else {
976+
foreach i $a j $b {if {$i ne $j} {return 0}}
977+
}
953978
return 1
954979
}
955980

@@ -1832,4 +1857,4 @@ namespace eval ::struct {
18321857
namespace import -force list::list
18331858
namespace export list
18341859
}
1835-
package provide struct::list 1.8.6
1860+
package provide struct::list 1.9

modules/struct/list.test.tcl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,26 @@ proc ::struct::list::test::main {} {
731731
expr {[equal $a $b] == [equal $b $a]}
732732
} 1
733733

734+
test equal-4.10 {equal command, -simple} {
735+
equal -simple [list [list a]] {{a}}
736+
} 1
737+
738+
test equal-4.11 {equal command, too many arguments} -body {
739+
equal -simple a b c
740+
} -returnCodes error -result {too many arguments after options}
741+
742+
test equal-4.12 {equal command, too many arguments} -body {
743+
equal a b c
744+
} -returnCodes error -result {too many arguments after options}
745+
746+
test equal-4.13 {equal command, bad option} -body {
747+
equal -x a a
748+
} -returnCodes error -result {Bad option "-x", expected -simple, or --}
749+
750+
test equal-4.14 {equal command, option break} -body {
751+
equal -- -a -a
752+
} -result 1
753+
734754
#----------------------------------------------------------------------
735755

736756
interp alias {} delete {} ::struct::list::list delete

modules/struct/pkgIndex.tcl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ package ifneeded struct::stack 1.5.4 [list source [file join $dir stack.tcl]
77
package ifneeded struct::tree 2.1.3 [list source [file join $dir tree.tcl]]
88
package ifneeded struct::pool 1.2.4 [list source [file join $dir pool.tcl]]
99
package ifneeded struct::record 1.2.4 [list source [file join $dir record.tcl]]
10-
package ifneeded struct::set 2.2.4 [list source [file join $dir sets.tcl]]
10+
package ifneeded struct::set 2.2.5 [list source [file join $dir sets.tcl]]
1111
package ifneeded struct::prioqueue 1.5 [list source [file join $dir prioqueue.tcl]]
1212
package ifneeded struct::skiplist 1.4 [list source [file join $dir skiplist.tcl]]
1313

1414
package ifneeded struct::graph 1.2.2 [list source [file join $dir graph1.tcl]]
1515
package ifneeded struct::tree 1.2.3 [list source [file join $dir tree1.tcl]]
1616

17-
package ifneeded struct::list 1.8.6 [list source [file join $dir list.tcl]]
18-
package ifneeded struct::list::test 1.8.5 [list source [file join $dir list.test.tcl]]
19-
package ifneeded struct::graph 2.4.4 [list source [file join $dir graph.tcl]]
20-
package ifneeded struct::map 1.1 [list source [file join $dir map.tcl]]
17+
package ifneeded struct::list 1.89 [list source [file join $dir list.tcl]]
18+
package ifneeded struct::list::test 1.8.5 [list source [file join $dir list.test.tcl]]
19+
package ifneeded struct::graph 2.4.4 [list source [file join $dir graph.tcl]]
20+
package ifneeded struct::map 1.1 [list source [file join $dir map.tcl]]
2121

2222
package ifneeded struct::matrix 2.2 [list source [file join $dir matrix.tcl]]
2323

modules/struct/sets.tcl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
# See the file "license.terms" for information on usage and redistribution
1010
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1111
#
12-
# RCS: @(#) $Id: sets.tcl,v 1.17 2008/03/09 04:24:37 andreas_kupries Exp $
13-
#
1412
#----------------------------------------------------------------------
1513

1614
# @mdgen EXCLUDE: sets_c.tcl
@@ -184,4 +182,4 @@ namespace eval ::struct {
184182
namespace export set
185183
}
186184

187-
package provide struct::set 2.2.4
185+
package provide struct::set 2.2.5

0 commit comments

Comments
 (0)