Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ef5deccdd0bd56878a9d7b540d8337c55c527d32
Ticket: a95309bf7057f8486a3aff8be658460631984d26
"lselect" to form a list from an existing list
User & Date: crshults on 2014-12-04 17:25:24
Changes

  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"