了解大括号的使用 [英] Understanding the usage of braces

查看:42
本文介绍了了解大括号的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Tcl/Tk,对 tcl 中花括号的使用感到困惑.

I'm learning Tcl/Tk and am confused on the usage of curly braces in tcl.

对我来说,它似乎既用于指示范围又用于声明字符串!这是一个错误(或功能)吗?

To me it seems to be used to both indicate scope and declare strings! Is this a bug (or feature)?

我的解释正确吗?

推荐答案

简而言之,

  • Tcl 的大括号就像 sh 的单引号一样——将单词(和行)分组而不进行插值.
  • Tcl 的双引号就像 sh 的双引号一样——允许插值.

proc 定义中使用花括号的事实不是强制性的.这只是将脚本作为参数传递给 proc 而无需插值的最便捷方式.

The fact that you use curly braces in a proc definition is not mandatory. It's just the most convenient way to pass a script as an argument to proc without interpolating.

这些是等价的

proc add3 {a b c} {
    return [expr {$a + $b + $c}]
}

proc add3_weird [list a b c] "return \[expr {\[set a] + \[set b] + \[set c]}]"

一旦您内化了 Tcl 引用,您就会意识到 Tcl 是多么灵活.

Once you internalize Tcl quoting, you'll realize how truly flexible Tcl can be.

这篇关于了解大括号的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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