用了很一段时间的Modelsim,用TCL脚本仿真,开始注意起来它,看了些资料,有一个问题始终让我很困惑,那就是花括号 的用法,今天Google了一下,觉得有一点豁然了,记录一下。为了不让自己的翻译影响大家理解,先给出原文,再翻译一下。

第一段:

THE RULE

SQUARE BRACKETS are used to define a block that's run BEFORE the rest of the command on the current line, and the result is substituted into the line.

CURLY BRACES are used to define a block that's deferred - in other words it may be run AFTER the rest of the command on the current line.

规则:

方括号是用来定义一个块,它在当前行的其余命令之前运行,并且结果替换到当前行中。

花括号是用来定义一个块,它是延期的,换句话说它会在当前行的其余命令之后运行。

第二段:

In Tcl, both Curley braces and double quotes can be used to hold a block of program or data together as a single unit / parameter ... but there are differences .

a) Curley braces can stretch over a number of lines, with new lines within the block being simply a part of the block. So they're ideal for defining blocks of code.

b) Curley braces can be nested - since there are different open and close characters, blocks within blocks are written easily and naturally, which is quite impractical with double quotes!

c) the biggest difference is that double quoted blocks are evaluated at the time they are encountered by the language parser, but curley braces are deferred until they are (perhaps) evaluated later under the control of the command of which they form a part.

在TCL中,花括号和双引号都可以用来把一块程序或数据组合起来成一个单元(参数),但是他们的用法有区别。

a)     花括号可以延续到若干行,可以在块内包含若干的新行。所以花括号很适合用来定义代码块。

b)     花括号可以嵌套。因为花括号左(open)右(close)不同的字符表示,所以块中嵌套的块可以被容易自然的书写,这时使用双引号是不实际的。

c)     最大的不同是TCL语言解释器在遇到双括号内的块时就进行估值,但是花括号是延期的,块在由它形成的不同的命令的控制下延迟估值。(翻译不太好,看原文)

看下面的例子

set sample 5

proc demo {} {global sample; return $sample}

proc omed {} "global sample; return $sample"

set sample 27

puts "Curley braces - defer substitution until block is run"

puts [demo]

puts "Double quotes - just grouping; substition at definition time"

puts [omed]

puts [info body demo]

puts [info body omed]

很多资料里说到花括号就是它阻止替换,但是在定义的过程中,如果不替换那么块中的命令根本无法执行。这就很矛盾。

其实,花括号也会替换,只是延迟了,不是很多地方说的不替换,也没有什么例外。只是这个延迟我们得好好体会一下。

顺便说一下,在有些资料里说TCL中的流程控制语句是说TCL对花括号的要求很严格之类的说法,其实TCL的“保留字”都是命令,命令和参数之间肯定得有空格,而且要换行又要保持命令的格式就得用花括号了,所以对于for之类的命令换行前都得有个open braces。

TCL 双引号和花括号的区别的更多相关文章

  1. include包含头文件的语句中,双引号和尖括号的区别

    include包含头文件的语句中,双引号和尖括号的区别   #include <>格式:引用标准库头文件,编译器从标准库目录开始搜索 #incluce ""格式:引用非 ...

  2. 双引号与尖括号的区别 and 相对路径与绝对路径

    包含头文件的时候,如果包含的是自己写的头文件是用" " .如果是包含系统的头文件,一般用<>. 相对路径与绝对路径

  3. include包含头文件的语句中,双引号和尖括号的区别是什么?

    include包含头文件的语句中,双引号和尖括号的区别是什么?  #include <> 格式:引用标准库头文件,编译器从标准库目录开始搜索 尖括号表示只在系统默认目录或者括号内的路径查找 ...

  4. PHP数组键值使用单引号和双引号和无符号的区别

    PHP数组键值使用单引号和双引号和无符号的区别 方法/步骤 1 第一种:$array['key']此单引号键值模式可以直接被解析为一个数组即$array 第二种:$array["key&qu ...

  5. C语言包含头文件时用引号和尖括号的区别

    用尖括号 #include <>:    一般用于包含标准的库头文件,编译器会去系统配置的库环境变量和者用户配置的路径去搜索,而不会在项目的当前目录去查找 用双引号 #include &q ...

  6. shell if条件判断中:双中括号与单中括号的区别

    电脑重装了系统,登录虚拟机的shell脚本需重写,在为编写的脚本命名时发现存在同名脚本,才想起来是连接公司服务器的登录脚本,不想写俩脚本,怕记混了,那就整合一下.代码如下: #!/bin/bash#z ...

  7. PHP中双引号和单引号的区别

    在PHP中,字符串数值有单引号和双引号两种. 区别: 单引号:系统不做复杂的转义.只转义\'和\\两种转义,其他的按原样输出. 双引号:则转义比较多,\",\\,\r,\t,\n,\$等. ...

  8. Python中小中花括号的区别

    Python主要有三种数据类型:字典.列表.元组.其分别由花括号.中括号.小括号表示. 如: 字典:dic={'a':12, 'b':34} 列表:list=[1,2,3,4] 元组:tup=(1,2 ...

  9. php中的双引号和单引号的区别?

    1.单引号里面的字符串直接全部转义,原样输出(即:单引号内部的变量不会被执行) 2.双引号里面的变量会被替换(即:变量会执行) 例如:$name = 'hello';echo "the $n ...

随机推荐

  1. bzoj1497

    这道题让我涨姿势了 对于这类问题,我们称作最大权闭合图问题 就是每个点都有一个点权,要求选择一个点集,其中每个点的指向的点也在点集中,使这样一个点权和最大 对于这种问题,我们添加源点s,汇点t 对于点 ...

  2. import project后,出现Unable to get system library for the project

    import project 后,出现Unable to get system library for the project. 这是因为在import 一个项目的时候,没有指定android sdk ...

  3. 搭建自己的NuGet服务器,上传自定义NuGet包

    第一步搭建NuGet服务器 创建空Web项目 安装Nuget服务,目前最新版本2.8.2 安装完成,会自动生产服务,出现如下界面 发布该网站,并部署至IIS 将.nupkg文件发布至网站的Packag ...

  4. Unity3d 巫师3Ciri的渲染

    --wolf96 16/10/6

  5. Clean Code – Chapter 3: Functions

    Small Blocks and Indenting The blocks within if statements, else statements, while statements, and s ...

  6. 六种简单方法提升ASP.NET Web API性能

    ASP.NET Web API 是非常棒的技术.编写 Web API 十分容易,以致于很多开发者没有在应用程序结构设计上花时间来获得很好的执行性能. 在本文中,我将介绍8项提高 ASP.NET Web ...

  7. mysql 一个较特殊的问题:You can't specify target table for update in FROM clause

    mysql 一个较特殊的问题:You can't specify target table for update in FROM clause 即:不能先select出同一表中的某些值,再update ...

  8. HW1.3

    public class Solution { public static void main(String[] args) { System.out.println(" J A V V A ...

  9. HW4.8

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  10. 委托demo

    delegate bool Filter(string s); class test { static void Main() { Filter f=new Filter(A); Display(ne ...