Overview
| Artifact ID: | 092d5c4cb147d12a5a39ecff59548696b74e715a |
|---|---|
| Ticket: | a95309bf7057f8486a3aff8be658460631984d26
"lselect" to form a list from an existing list |
| User & Date: | crshults on 2014-12-04 17:01:39 |
Changes
- 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"