Tcl 中有获取连续数字数组的简写吗?
例如,在 Perl 中,要获取从 1 到 10 的数字的顺序数组,您可以简单地执行以下操作:
@myArray = (1 .. 10);
这两个句点用作此操作的简写,而不是创建 for 循环或手动写出整个内容。我使用过的其他语言也有类似的东西。
Tcl 中是否存在类似的简写?
For example, in Perl, to get a sequential array of numbers from 1 to 10, you could simply do:
@myArray = (1 .. 10);
The two periods serve as shorthand for this operations instead of making a for loop or writing the whole thing out manually. Other languages I've used have something similar also.
Does a similar shorthand exist in Tcl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以定义该方法:
并将其用作:
您甚至可以美化过程的调用,使其看起来像在 perl 中一样。为此,只需重新定义
unknown
过程:之后您可以简单地编写为:
:)
You can define the method:
And use it as:
You even can beautify the call of procedure to make it look as in perl. For that just redefine
unknown
procedure:After that you can write just simple as:
:)
不完全是这个,但
也可以在 this 中搜索“iota”关键字,看看如何使用一行。
Not quite this one, but
Also search this for the "iota" keyword to see how this can be done using a one-liner.
除了表达式(它们自己的小语言)之外,Tcl 没有运算符,并且始终是严格前缀驱动的语言。这意味着没有这样方便的循环简写。另一方面,Tcl 的标准命令没有什么特别之处(除了一些在这里无关紧要的小效率细节),因此制作自己的命令没有问题:
您可以通过使用未知处理程序来伪造中缀运算符(如 GrAnd 的回答) )但是与上面相比,这确实相当慢。
With the exception of expressions (which are their own little language) Tcl has no operators and is always a strictly prefix-driven language. This means that there isn't such a convenient shorthand for doing loops. On the other hand, there's nothing particularly special about Tcl's standard commands (apart from some minor efficiency details that don't matter here) so making your own is no problem:
You can fake infix operators by using an unknown handler (as in GrAnd's answer) but that's really quite slow by comparison with the above.
不,tcl 中不存在类似的简写。
如果您确实想要速记,您可以创建自己的看起来几乎相同的命令。例如:
No, a similar shorthand does not exist in tcl.
If you really want shorthand, you can create your own command that looks almost the same. For example: