Selecting multiple elements of a list? 
Author Message
 Selecting multiple elements of a list?

I have an application where it would convenient to select multiple
elements from a list at once.  I've written:

proc lselect { listIn indices } {
    set listOut {}
    foreach i $indices {
        lappend listOut [lindex $listIn $i]
    }
    return $listOut

Quote:
}

But I wonder how much faster this would be in C which led me to wonder
about letting [lindex] take a LIST of indices as the second argument.
Any thoughts?

                                   Chris
--
Chris Nelson                               As MIT is not "Massachusetts"




Tue, 18 Jul 2000 03:00:00 GMT  
 Selecting multiple elements of a list?

Quote:

> I have an application where it would convenient to select multiple
> elements from a list at once.  I've written:

> proc lselect { listIn indices } {
>     set listOut {}
>     foreach i $indices {
>         lappend listOut [lindex $listIn $i]
>     }
>     return $listOut
> }

> But I wonder how much faster this would be in C which led me to wonder
> about letting [lindex] take a LIST of indices as the second argument.
> Any thoughts?

>                                    Chris
> --
> Chris Nelson                               As MIT is not "Massachusetts"



Sounds cool.  And if elements of the indices list could themselves be ranges then
lindex functionality could subsume lrange.  Also, it-would-be-nice-if indices could
allow expressions that include 'end' so that we can ask for things like:
        set result [lindex $list {0 2} {end-2 end}]
to get the first three and the last three elements, or even:
        set result [lindex $list {end end-2}]
to get the last three elements of the list in reversed order.

John Ellson



Tue, 18 Jul 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. how to delete multiple elements from a list

2. Multiple select in a list ??

3. Multiple select of list items

4. Multiple select scroll lists?

5. multiple listboxes with multiple select

6. Intersection of multiple lists/list of lists

7. confused about adding elements to a list with list.append(otherlist)

8. Deleting list of elements from a list

9. common elements in list of list

10. list -> elements of list

11. print select elements from array

12. Return of selected element in listcontrol

 

 
Powered by phpBB® Forum Software