Skip to content
Tcl Source Code History Of Ticket a95309bf7057f848
Login

History Of Ticket a95309bf7057f848

Artifacts Associated With Ticket a95309bf7057f848

  1. Ticket change [2dac72d826] (rid 136450) by anonymous on 2014-01-12 00:50:14:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. 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
      }
      
    5. is_private initialized to: "0"
    6. login: "anonymous"
    7. priority initialized to: "5 Medium"
    8. private_contact initialized to: "c1589a2fa4fc7951c4aba10439d3b95af55c3a63"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "anonymous"
    13. subsystem initialized to: "- New Builtin Commands"
    14. title initialized to: ""lselect" to form a list from an existing list"
    15. type initialized to: "RFE"
  2. Ticket change [05d9191056] (rid 136459) by dkf on 2014-01-13 19:39:41:

    1. assignee changed to: "dkf"
    2. login: "dkf"
    3. mimetype: "text/plain"
    4. subsystem changed to: "17. Commands I-L"
  3. Ticket change [092d5c4cb1] (rid 140813) by crshults on 2014-12-04 17:01:39:

    1. 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.
      
    2. login: "crshults"
    3. mimetype: "text/plain"
  4. Ticket change [ef5deccdd0] (rid 140814) by crshults on 2014-12-04 17:25:24:

    1. 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};
      
    2. login: "crshults"
    3. mimetype: "text/plain"
  5. Ticket change [d72d074b1c] (rid 140921) by dkf on 2014-12-11 10:43:33:

    1. 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>
      
    2. login: "dkf"
    3. mimetype: "text/html"
    4. username: "dkf"
  6. Ticket change [976d13e49f] (rid 145211) by anonymous on 2016-03-06 15:25:55:

    1. closedate changed to: "2457454.14300752"
    2. closer changed to: "anonymous"
    3. icomment:
      I'm the reporter. Since this is not quite appropriate for the Tcl core, I'm closing this ticket.
      
    4. login: "anonymous"
    5. mimetype: "text/plain"
    6. status changed to: "Closed"