用tcl处理多维列表很困难 [英] It is difficult to handle multiple dimension list with tcl

查看:41
本文介绍了用tcl处理多维列表很困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用 tcl 处理一些复杂的数据.我需要 3 维列表来存储数据,但我发现 tcl 对这项工作不利.

I need to handle kind of complex data with tcl. I need 3 dimension list to store the data, but I find tcl is bad for this work.

根据我目前的研究,tcl 不支持列表的简单索引,如:listname(index).

Based on my current study, tcl does not support simple index of list like: listname(index).

所以对于多维列表,如果我想为某个元素分配一个新的值,会很麻烦.

So for multiple dimension list, if I want to assign a new value for certain element, it will be very troubling.

是否有一些技巧可以有效地处理数据?

Are there some skills to handling data effectively?

推荐答案

多维数组最有效的表示是嵌套列表(除非您要使用稀疏数组).为了解决这个问题,你有 lrepeat 用于创建,多索引 lindex 用于读取,以及 lset 用于写入.

The most efficient representation for a multi-dimensional array is a nested list (unless you're going for a sparse array). To help with this, you have lrepeat for creation, multi-index lindex for reading, and lset for writing.

# Create a 5x5x5 structure, filled with float zeroes
set example [lrepeat 5 [lrepeat 5 [lrepeat 5 0.0]]]

# Index into the structure
set value [lindex $example 1 2 3]

# Write a value back into the structure
lset example 1 2 3 [expr {$value + 8.75}]

该实现对列表(包括嵌套列表)使用了高效的写时复制方案,以便您在可能的情况下节省空间并在必要时将重复降至最低,以保持这种错觉,即通过积极的复制,这一切都是纯粹的价值.除了更快……

The implementation uses an efficient copy-on-write scheme for lists (including nested lists) so that you get space-saving where possible and minimal duplication where necessary in order to maintain the illusion that it's all a pure value with aggressive copying. Except much faster…

当然,如果你经常这样做,你最好看看VecTcl.

Of course, if you're doing this a lot, you might be better off having a look at VecTcl.

这篇关于用tcl处理多维列表很困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆