Artifacts Associated With Ticket a95309bf7057f848
Ticket change [2dac72d826] (rid 136450) by anonymous on 2014-01-12 00:50:14:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/plain"
- comment initialized to:
~ Prototype lselect list element1 ?element2 ...? ~ Example set l {a b c} lselect $l 0 2 # a c lselect $l 0 # a lselect $l 0 1 2 # a b c lselect $l 4 # {} according to [lindex] ~ One implementation proc lselect {l args} { foreach index $args { lappend result [lindex $l $index] } return $result } - is_private initialized to: "0"
- login: "anonymous"
- priority initialized to: "5 Medium"
- private_contact initialized to: "c1589a2fa4fc7951c4aba10439d3b95af55c3a63"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "anonymous"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to: ""lselect" to form a list from an existing list"
- type initialized to: "RFE"
Ticket change [05d9191056] (rid 136459) by dkf on 2014-01-13 19:39:41:
- assignee changed to: "dkf"
- login: "dkf"
- mimetype: "text/plain"
- subsystem changed to: "17. Commands I-L"
Ticket change [092d5c4cb1] (rid 140813) by crshults on 2014-12-04 17:01:39:
- icomment:
This is [lindex] for the user who wants to retrieve multiple indices from the source list, so I think the name should be [lindices] Implementation: proc lindices {the_list args} { if {[llength $args]} { set result {} foreach index [join $args] { if {$index < [llength $the_list]} { lappend result [lindex $the_list $index] } } return $result } return $the_list } Example Usage: lindices {a b c} # returns the original list as lindex does lindices {a b c} 0 lindices {a b c} 1 lindices {a b c} 3 # returns nothing as lindex does lindices {a b c} 0 1 3 lindices {a b c} {0 1 3} # args list can be a list My opinion is this is something simple enough for the user to implement in Tcl and place in their personal library/toolbox. I keep mine in lib/tcl/8.6/list_tools-1.0.0.tm along with others like [lremove] [lrotate] [lpop] etc. - login: "crshults"
- mimetype: "text/plain"
- icomment:
Ticket change [ef5deccdd0] (rid 140814) by crshults on 2014-12-04 17:25:24:
- icomment:
Updated implementation to stay a little more true to [lindex] behaviour: proc lindices {the_list args} { if {[llength $args]} { set result {} foreach index [join $args] { if {[string is integer $index]} { if {$index >= 0 && $index < [llength $the_list]} { lappend result [lindex $the_list $index] } } else { lappend result [lindex $the_list $index] } } return $result } return $the_list } Updated Example Usage: lindices {a b c}; # returns the original list as lindex does lindices {a b c} 0; lindices {a b c} 1; lindices {a b c} 3; # returns nothing as lindex does lindices {a b c} 0 1 3; lindices {a b c} {0 1 3}; # args list can be a list lindices {a b c} -1; # returns nothing as lindex does lindices {a b c} x; # bad index "x": must be integer?[+-]integer? or end?[+-]integer? lindices {a b c} {0 1 end 0 3 end-1}; - login: "crshults"
- mimetype: "text/plain"
- icomment:
Ticket change [d72d074b1c] (rid 140921) by dkf on 2014-12-11 10:43:33:
- icomment:
Would this be a reasonable implementation? <verbatim> proc lselect {list args} { lmap index $args {lindex $list $index} } </verbatim> Remember that this will support lists of indices too. Cut-n-paste from a session: <verbatim> % lselect {a {b c {d e}} f {g h}} {1 1} 1 3 {1 2 0} c {b c {d e}} {g h} d </verbatim> - login: "dkf"
- mimetype: "text/html"
- username: "dkf"
- icomment:
Ticket change [976d13e49f] (rid 145211) by anonymous on 2016-03-06 15:25:55:
- closedate changed to: "2457454.14300752"
- closer changed to: "anonymous"
- icomment:
I'm the reporter. Since this is not quite appropriate for the Tcl core, I'm closing this ticket.
- login: "anonymous"
- mimetype: "text/plain"
- status changed to: "Closed"