Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-07-29
19:53 • Ticket [747083ffff] lsearch -command tclcmd -group grpsize, lsort -group grpsiz... artifact: 90fdf00e05 user: dkf
2009-01-30
20:49 • Ticket [747083ffff]: 6 changes artifact: 05a3a42630 user: dkf
2008-11-02
18:33 • Ticket [747083ffff]: 5 changes artifact: 587a927a32 user: dkf
2008-09-29
15:51 • Closed ticket [747083ffff]. artifact: b75aeed601 user: dkf
2008-08-29
23:36 • Ticket [747083ffff]: 4 changes artifact: 282fa886e1 user: kieranelby
2003-08-15
13:41 • Ticket [747083ffff]: 4 changes artifact: 33a587776f user: mic42
2003-06-02
17:56 • Ticket [747083ffff]: 2 changes artifact: d930296c7a user: dkf
2003-06-01
17:17 • New ticket [747083ffff]. artifact: ad3ef2c2d6 user: nobody

lsearch -command tclcmd -group grpsize, lsort -group grpsiz

Closed747083ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 17 years ago
Descriptionplain2003-06-01 17:17:57
improve lsearch by adding a  -command tclcmd option 
to search list items using the same function as lsort

e.g.
  set L [lsort -command CompareVector $L]
  set X [lsearch -sorted -command CompareVector $L]

also some grouping would be great:
think you have a list with every 4 items belong to a 
group and you wanna sort it by the third item:
e.g. 
set L { a0 a1 a2 a3  b0 b1 b2 b3  c0 c1 c2 c3 .. }

to sort using lsort you have to make a list of lists by
  set L2 {}
  foreach {a b c d} { lappend L2 [list $a $b $c $d] }
  set L2 [lsort -index 2 $L2]
  set L [concat $L2]

a faster approach with the nonexisting -group option
  set L [lsort -group 4 -index 2 $L]

searching such lists is required than as well so
  lsearch -group 4 -index 2 $L  c2

will return 2 the group number (my favourite, or 10 as the 
real index, or 8 as the first member of the group)

such grouped lists are very general in my opinion, 
because regexp,array get,split are functions that may 
return such lists

finally a quick   "lreverse list" command would be a nice 
idea.
dkf Ticket [747083ffff]: 2 changes [History diff]2003-06-02 17:56:20
mic42plain2003-08-15 13:41:09
Logged In: YES 
user_id=302287

The TIP #127 implementation could help with a part of this
internally. 

Implementing -group could basically consists of a
preprocessing step to create sublists for internal use, that
get flattend out after searching or sorting is done. Could
give quite complex interactions with the -index option if
used on nested lists.  

Implementing -command is trivial, just copy the code from lsort.

It would have fit in quite well for TIP #127, but i didn't
see it requested here and no comment was added to the TIP
(or mailed to me).
kieranelbyplain2008-08-29 23:36:24
Logged In: YES 
user_id=99072
Originator: NO

I've often thought the ability to directly sort a
name-value style of list would be rather useful,
and fancied some exercise in Tcl internals, so I've
created patch 2082681 which adds a "-group" option to lsort:

https://sourceforge.net/tracker/?func=detail&aid=2082681&group_id=10894&atid=310894

When using -group in conjunction with the multiple index
form of -index, it seemed to make most sense to have
-group consume the first index given to -index, and
use that as the offset within each group.

e.g.
% lsort -group 3 -index {0 1} \
    {{Bob Smith} 25 Audi {Jane Doe} 40 Ford}
{{Jane Doe} 40 Ford {Bob Smith} 25 Audi}

(since Smith is index 1 of element 0 of the first group of 3,
and it sorts after Doe in the corresponding position in the
2nd group of 3).

I might get round to a patch for lsearch and a TIP at some
point ...
dkf Closed ticket [747083ffff]. [History diff]2008-09-29 15:51:20
dkfplain2008-11-02 18:33:33
data_type - 210894
dkfplain2009-01-30 20:49:11
allow_comments - 1
dkfplain2009-07-29 19:53:42
IP - Comment Removed: 130.88.1.31
Log in (anonymous is fine) to add a comment.