|
2015-04-20
| ||
| 20:32 | • Closed ticket [862526872c]: Getting another object of the same type in dict and ... artifact: 376dc94f84 user: ferrieux | |
| 17:44 | • New ticket [862526872c]. artifact: 91d0711c7a user: anonymous | |
Getting another object of the same type in dict and list for performance
Closed / Invalid862526872cda074626d8a1e020479acf44ed7009Created 12 years agoUpdated 12 years ago
Descriptionplain2015-04-20 17:44:24
When getting an element of a list using "lindex" or getting an element of a dict using "dict get", the procedure returns a string.
In the situation that some user wants to traverse recursively this data structure, or wants simply a subnode of this data structure for processing he has to convert the string into a dict or a list again.
I would be nice a subcommand similar to this:
- dict subnode key? key? key? ...
- list subnode key? key? key? ...
This subcommand returns the subnode with the same type as the container for that key. I mean that "dict subnode" should returns another dict and "list subnode" another list.
This new subcommand would be interesting for performance manipulating complex data structures.
This script shows that "dict get" and "lindex" returns a string object instead of a dict or list object:
set a [list 1 2 {1 1 2332 {12 12} } 23]
puts "a inner representation: \n\t[::tcl::unsupported::representation $a]\n"
set b [lindex $a 2]
puts "b inner representation: \n\t[::tcl::unsupported::representation $b]\n"
set c [dict create key1 val1 key2 {key21 val21 key22 {key221 val221} } key3 val3]
puts "c inner representation: \n\t[::tcl::unsupported::representation $c]\n"
set d [dict get $c key2 key22]
puts "d inner representation: \n\t[::tcl::unsupported::representation $d]\n"
ferrieuxplain2015-04-20 20:32:19
There is no such thing as a "force to string" by either list or dict containers; they do respect whatever current representation their contents have.
In the examples given, constant *strings* like {1 1 2332 {12 12} } are passed in and gotten out. Make them shimmer before encapsulation, they'll keep their state:
set x {1 2 3 4}
lindex $x 0
set a [list $x $x $x]
set b [lindex $a 2]
puts "b inner representation: \n\t[::tcl::unsupported::representation $b]\n"
=>
b inner representation:
value is a list with a refcount of 8, object pointer at 0x8daa208, internal representation 0x8df8db8:(nil), string representation "1 2 3 4"
Log in (anonymous is fine) to add a comment.