---
title: "Tcl (最早称为“工具命令语言”\"Tool Command Language\", 由John Ousterhout创建"
author: "universsky"
date: "2013-05-22T15:17:00Z"
tags: []
slug: "tcl-tool-command-language-john-ousterhout"
draft: false
lastmod: "2014-04-23T16:51:33Z"
id: 2053452
url: "https://universsky.iteye.com/blog/2053452"
---

**应用**

(1)：作为批次处理语言或工作控制语言。许多脚本语言用来执行一次性任务，尤其是[系统管理](http://baike.baidu.com/view/635537.htm)方面。DOS，[Windows](http://baike.baidu.com/view/4821.htm)的[批处理](http://baike.baidu.com/view/80110.htm)文件和[Unix](http://baike.baidu.com/view/8095.htm)的[shell](http://baike.baidu.com/view/849.htm)脚本都属于这种应用；

(2)：作为通用的编程语言存在，如[Perl](http://baike.baidu.com/view/46614.htm)、[Python](http://baike.baidu.com/view/21087.htm)、[Ruby](http://baike.baidu.com/view/45135.htm)等。由于“解释执行，[内存管理](http://baike.baidu.com/view/4541016.htm)，动态”等特性，它们仍被称为脚本语言。但它们已经用于应用程序编写，用户也不把它们看作脚本语言；

(3)：许多大型的应用[程序](http://baike.baidu.com/view/17674.htm)都包括根据[用户](http://baike.baidu.com/view/200012.htm)需求而定制的惯用脚本语言。同样地，许多电脑[游戏](http://baike.baidu.com/view/2468.htm)系统使用一种自定义脚本语言来表现[NPC](http://baike.baidu.com/view/704.htm)(Non-Player Character，Non-Playable Character，Non-Player Class)和游戏环境的预编程动作。此类语言通常是为一个单独的应用程序所设计，虽然它们貌似一些通用语言(如Quake C，Modeled After C)，但它们有自定义的功能；

(4)：网页中的嵌入式脚本语言。熟知的[HTML](http://baike.baidu.com/view/692.htm)(Hyper Text Mark-up Language)即[超文本标记语言](http://baike.baidu.com/view/383720.htm)，就是一种脚本语言，它的解释器就是[浏览器](http://baike.baidu.com/view/7718.htm)。[JavaScript](http://baike.baidu.com/view/16168.htm)直到现在仍然是网页[浏览器](http://baike.baidu.com/view/7718.htm)内的主要编程语言，它的ECMAScript标准化保证了它成为流行的通用嵌入式脚本语言。另外，随着[动态网页](http://baike.baidu.com/view/348756.htm)技术发展，[ASP](http://baike.baidu.com/view/2616.htm)、[JSP](http://baike.baidu.com/view/3387.htm)、PHP等嵌入网页的脚本语言正被广泛使用，不过这些脚本要通过Web Server解释,而Html则被浏览器执行；

(5)：脚本语言在系统应用程序中嵌入使用，作为用户与系统的接口方式。在工业控制领域，PLC编程、组态软件的脚本语言是扩充组态[系统](http://baike.baidu.com/view/25302.htm)功能的重要手段；在通信平台领域，[IVR](http://baike.baidu.com/view/13766.htm)(自动语音应答)流程编程；Office办公软件，提供的宏和VBA；其他应用软件如ER Studio提供的Basic MacroEditor，用户可以编写Sax Basic脚本操作ER图，生成Access库、导出Word文档等扩展功能。\[8]

**一、发展情况**

脚本技术得益于计算机[硬件](http://baike.baidu.com/view/25278.htm)的加速发展。某些情况下甚至系统程序设计语言也不够有效，因此不得不用汇编编写应用程序。而今的机器比1980年的快100～500倍，且仍在以每18个月翻一番的速度增长。计算机性能快速提高，使计算机程序越来越复杂。因此，开发时间已远比运行时间紧迫。这时，脚本语言作为系统程序设计语言的补充，开始被主要的[计算机](http://baike.baidu.com/view/3314.htm)平台所同时提供。[编程语言](http://baike.baidu.com/view/552871.htm)已经由性能低下的硬件与执行效率之间的矛盾，转变为快速变化的市场需要与低效的开发工具之间的矛盾，所以脚本语言的发展在软件开发中有着必然的趋势

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/76320.htm)

Tcl (最早称为“工具命令语言”"Tool Command Language", 但是目前已经不是这个含义，不过我们仍然称呼它为TCL)是一种 [脚本语言](http://baike.baidu.com/view/76320.htm)。 由John Ousterhout创建。 TCL很好学，功能很强大。TCL经常被用于 [快速原型](http://baike.baidu.com/view/408667.htm)开发，脚本编程， GUI和测试等方面。

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

\* 任何东西都是一条命令，包括语法结构(for, if等)。

\* 任何事物都可以重新定义和重载。

\* 所有的[数据类型](http://baike.baidu.com/view/675645.htm)都可以看作字符串。

\* 语法规则相当简单

\* 提供[事件驱动](http://baike.baidu.com/view/536048.htm)给[Socket](http://baike.baidu.com/view/13870.htm)和文件。基于时间或者用户定义的事件也可以。

\* 动态的域定义。

\* 很容易用[C](http://baike.baidu.com/view/10075.htm),[C++](http://baike.baidu.com/view/824.htm),或者[Java](http://baike.baidu.com/view/29.htm)扩展。

\*[解释语言](http://baike.baidu.com/view/1538994.htm)，代码能够动态的改变。

\* 完全的[Unicode](http://baike.baidu.com/view/40801.htm)支持。

\* 平台无关。[Win32](http://baike.baidu.com/view/270236.htm),[UNIX](http://baike.baidu.com/view/8095.htm),[Mac](http://baike.baidu.com/view/32702.htm)上都可以跑。

\* 和[Windows](http://baike.baidu.com/view/4821.htm)的GUI紧密集成;[Tk](http://baike.baidu.com/view/44997.htm)

\* 代码紧凑，易于维护。

TCL本身不提供[面向对象](http://baike.baidu.com/view/125370.htm)的支持。但是语言本身很容易扩展到支持[面向对象](http://baike.baidu.com/view/125370.htm)。许多[C语言](http://baike.baidu.com/view/1219.htm)扩展都提供[面向对象](http://baike.baidu.com/view/125370.htm)能力，包括XOTcl,[Incr Tcl](http://baike.baidu.com/view/6326724.htm)等。另外SNIT扩展本身就是用TCL写的。

使用最广泛的TCL扩展是[TK](http://baike.baidu.com/view/44997.htm)。 TK提供了各种[OS](http://baike.baidu.com/view/34963.htm)平台下的[图形用户界面](http://baike.baidu.com/view/185360.htm)GUI。连强大的[Python](http://baike.baidu.com/view/21087.htm)语言都不单独提供自己的GUI，而是提供接口适配到TK上。另一个流行的扩展包是[Expect](http://baike.baidu.com/view/1604222.htm). Expect提供了通过[终端](http://baike.baidu.com/view/105503.htm)自动执行命令的能力，例如([passwd](http://baike.baidu.com/view/1116984.htm),[ftp](http://baike.baidu.com/view/369.htm),[telnet](http://baike.baidu.com/view/44255.htm)等命令驱动的外壳).

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

下面是TCL[程序](http://baike.baidu.com/view/17674.htm)的例子：

#!/bin/sh

\# next line restarts using tclsh in path \\

exec tclsh ${1+"$@"}

\# echo server that can handle multiple

\# simultaneous connections.

proc newConnection { sock addr port } {

\# client connections will be handled in

\# line-buffered, non-blocking mode

fconfigure $sock -blocking no -buffering line

\# call handleData when[socket](http://baike.baidu.com/view/13870.htm)is readable

fileevent $sock readable \[ list handleData $sock ]

}

proc handleData {

puts $sock \[ gets $sock ]

if { \[ eof $sock ] } {

close $sock

}

}

\# handle all connections to port given

\# as argument when server was invoked

\# by calling newConnection

set port \[ lindex $argv 0 ]

[socket](http://baike.baidu.com/view/13870.htm)-server newConnection $port

\# enter the event loop by waiting

\# on a dummy variable that is otherwise

\# unused.

vwait forever

另外一个[TK](http://baike.baidu.com/view/44997.htm)的例子 (来自 A simple A/D clock) 它使用了[定时器](http://baike.baidu.com/view/281961.htm)时间，3行就显示了一个时钟。

proc every {ms[body](http://baike.baidu.com/view/463095.htm)} {eval $body; after $ms \[info level 0]}

pack \[label .clock -textvar time]

every 1000 {set ::time \[clock format \[clock sec] -format %H:%M:%S]} ;# RS

解释：第一行定义了过程every， 每隔ms[毫秒](http://baike.baidu.com/view/251176.htm)，就重新执行[body](http://baike.baidu.com/view/463095.htm)代码。第二行创建了标签起内容由time[变量](http://baike.baidu.com/view/296689.htm)决定。第3行中设置[定时器](http://baike.baidu.com/view/281961.htm)，time[变量](http://baike.baidu.com/view/296689.htm)从当前时间中每秒更新一次。

Tcl被广泛的用做script语言，大多数情况下，Tcl和Tk(“Tool Kit”)库同时使用，Tk是一系列令Tcl易于编写图形[用户接口](http://baike.baidu.com/view/1309799.htm)的命令和过程

Tcl的一个重要特性是它的扩展性。如果一个[程序](http://baike.baidu.com/view/17674.htm)需要使用某些标准Tcl没有提供的功能，可以使用[c语言](http://baike.baidu.com/view/1219.htm)创造一些新的Tcl命令，并很容易的融合进去。正是由于Tcl易于扩展，很多人为它编写了扩展包，并在网上共享。

Tcl和其他编程语言例如c不同，它是一种[解释语言](http://baike.baidu.com/view/1538994.htm)而非编译语言。Tcl[程序](http://baike.baidu.com/view/17674.htm)由一系列Tcl命令组成，在运行时由Tcl[解释器](http://baike.baidu.com/view/592974.htm)解释运行。解释运行的一个优点是它可以自己为自己生成Tcl script。

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

## 参数定义

Tcl的Procedures 和c的函数差不多. 它们有参数，它们返回值。基本定义方法是：

proc name argList[body](http://baike.baidu.com/view/463095.htm)

当一个procedure被定义，它就被看做是一个命令，如同Tcl的自带命令一样，通过名字来呼叫，名字后面跟上参数。

缺省的，procedure的返回值是它的最后一个命令结果。但也可以通过return命令来返回其他值。Return值可以在procedure的任何地方，一旦执行，procedure就此返回。

Example 5.1:

proc sum\_proc {a b} {

return \[expr $a + $b]

}

proc magnitude {num} {

if {$num &gt; 0} {

return $num

}

set num \[expr $num * (-1)]

return $num

}

set num1 12

set num2 14

set sum \[sum\_proc $num1 $num2]

puts "The sum is $sum"

puts "The magnitude of 3 is \[magnitude 3]"

puts "The magnitude of -2 is \[magnitude -2]"

Output:

The sum is 26

The magnitude of 3 is 3

The magnitude of -2 is 2

在procedure中可以通过set创造[变量](http://baike.baidu.com/view/296689.htm)，但是变量只在procedure中有效，而且一旦procedure返回，这些变量就不可访问。如果procedure需要访问主[程序](http://baike.baidu.com/view/17674.htm)中的[变量](http://baike.baidu.com/view/296689.htm)，就需要使用global[关键字](http://baike.baidu.com/view/390935.htm)。

Example 5.2:

proc dumb\_proc {} {

set myvar 4

puts "The value of the local variable is $myvar"

global myglobalvar

puts "The value of the global variable is $myglobalvar"

}

set myglobalvar 79

dumb\_proc

Output:

The value of the local variable is 4

The value of the global variable is 79

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

## 变量

不像c，Tcl的[变量](http://baike.baidu.com/view/296689.htm)在使用前不需要声明。Tcl的[变量](http://baike.baidu.com/view/296689.htm)在它首次被赋值时产生，使用set命令。[变量](http://baike.baidu.com/view/296689.htm)可以用unset命令删除，虽然并不强制需要这样做。

[变量](http://baike.baidu.com/view/296689.htm)的值通过$符号访问，也叫变量交换。

Tcl是一个典型的”弱类型定义”语言，这意味者任何类型可以存储在任何[变量](http://baike.baidu.com/view/296689.htm)中。例如，同一个[变量](http://baike.baidu.com/view/296689.htm)可以存储数字，日期，字符串甚至另一段Tcl script.

Example 1.1:

set foo "john"

puts "Hi my name is $foo"

Output: Hi my name is john

Example 1.2:

set month 2

set day 3

set year 97

set date "$month:$day:$year"

puts $date

Output: 2:3:97

Example 1.3:

set foo "puts hi"

eval $foo

Output: hi

在这个例子里，[变量](http://baike.baidu.com/view/296689.htm)foo存储了另外一段Tcl script.

[表达式](http://baike.baidu.com/view/420676.htm)

包括数学[表达式](http://baike.baidu.com/view/420676.htm)，[关系表达式](http://baike.baidu.com/view/3524120.htm)，通常用 expr命令。

Example 2.1:

expr 0 == 1

Output: 0

Example 2.2:

expr 1 == 1

Output: 1

两数比较，true则输出1，false输出0

Example 2.3:

expr 4 + 5

Output: 9

Example 2.4:

expr sin(2)

Output: 0.909297

命令传递

以运算结果替代Tcl命令中的部分

Example 3.1:

puts "I am \[expr 10 * 2] years old, and my I.Q. is \[expr 100 - 25]"

Output: I am 20 years old, and my I.Q. is 75

方括号是命令传递的标志

Example 3.2:

set my\_height 6.0

puts "If I was 2 inches taller, I would be \[expr $my\_height + (2.0 / 12.0)] feet tall"

Output: If I was 2 inches taller, I would be 6.16667 feet tall

命令流控制

Tcl有判断流转(if-else; switch)和循环控制(while; for; foreach)

Example 4.1:

set my\_planet "earth"

if {$my\_planet == "earth"} {

puts "I feel right at home."

} elseif {$my\_planet == "venus"} {

puts "This is not my home."

} else {

puts "I am neither from Earth, nor from Venus."

}

set temp 95

if {$temp &lt; 80} {

puts "It's a little chilly."

} else {

puts "Warm enough for me."

}

Output:

I feel right at home.

Warm enough for me.

Example 4.2:

set num\_legs 4

switch $num\_legs {

2 {puts "It could be a human."}

4 {puts "It could be a cow."}

6 {puts "It could be an ant."}

8 {puts "It could be a spider."}

default {puts "It could be anything."}

}

Output:

It could be a cow.

Example 4.3:

for {set i 0} {$i &lt; 10} {incr i 1} {

puts "In the for loop, and i == $i"

}

Output:

In the for loop, and i == 0

In the for loop, and i == 1

In the for loop, and i == 2

In the for loop, and i == 3

In the for loop, and i == 4

In the for loop, and i == 5

In the for loop, and i == 6

In the for loop, and i == 7

In the for loop, and i == 8

In the for loop, and i == 9

Example 4.4:

set i 0

while {$i &lt; 10} {

puts "In the while loop, and i == $i"

incr i 1

}

Output:

In the while loop, and i == 0

In the while loop, and i == 1

In the while loop, and i == 2

In the while loop, and i == 3

In the while loop, and i == 4

In the while loop, and i == 5

In the while loop, and i == 6

In the while loop, and i == 7

In the while loop, and i == 8

In the while loop, and i == 9

Example 4.5:

foreach vowel {a e i o u} {

puts "$vowel is a vowel"

}

Output:

a is a vowel

e is a vowel

i is a vowel

o is a vowel

u is a vowel

Procedures

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

## 数组

Lists就好像是Tcl中的一种特殊的[数组](http://baike.baidu.com/view/209670.htm)。它把一堆东西放成一个集合，然后就像操作一个整体一样的操作它。

Example 6.1:

set simple\_list "John Joe Mary Susan"

puts \[lindex $simple\_list 0]

puts \[lindex $simple\_list 2]

Output:

John

Mary

注意list的index是从0开始的

Example 6.2:

set simple\_list2 "Mike Sam Heather Jennifer"

set compound\_list \[list $simple\_list $simple\_list2]

puts $compound\_list

puts \[llength $compound\_list]

Output:

{John Joe Mary Susan} {Mike Sam Heather Jennifer}

2

Example 6.3:

set mylist "Mercury Venus Mars"

puts $mylist

set mylist \[linsert $mylist 2 Earth]

puts $mylist

lappend mylist Jupiter

puts $mylist

Output:

Mercury Venus Mars

Mercury Venus Earth Mars

Mercury Venus Earth Mars Jupiter

Arrays

Tcl[数组](http://baike.baidu.com/view/209670.htm)在使用前无须定义，大小也不用指定。

Example 7.1:

set myarray(0) "Zero"

set myarray(1) "One"

set myarray(2) "Two"

for {set i 0} {$i &lt; 3} {incr i 1} {

puts $myarray($i)

}

Output:

Zero

One

Two

Example 7.2:

set person\_info(name) "Fred Smith"

set person\_info(age) "25"

set person\_info(occupation) "Plumber"

foreach thing {name age occupation} {

puts "$thing == $person\_info($thing)"

}

Output:

name == Fred Smith

age == 25

occupation == Plumber

这个例子指出[数组](http://baike.baidu.com/view/209670.htm)的index不需要是数字，其他类型的数据也可以。

Example 7.3:

set person\_info(name) "Fred Smith"

set person\_info(age) "25"

set person\_info(occupation) "Plumber"

foreach thing \[array names person\_info] {

puts "$thing == $person\_info($thing)"

}

Output:

occupation == Plumber

age == 25

name == Fred Smith

Strings

字符串是Tcl中最常用的类型，string有很多使用参数，可以参照Tcl手册。使用方法：

string option arg arg ...

Example 8.1:

set str "This is a string"

puts "The string is: $str"

puts "The length of the string is: \[string length $str]"

puts "The character at index 3 is: \[string index $str 3]"

puts "The characters from index 4 through 8 are: \[string range $str 4 8]"

puts "The index of the first occurrence of letter \\"i\\" is: \[string first i $str]"

Output:

The string is: This is a string

The length of the string is: 16

The character at index 3 is: s

The characters from index 4 through 8 are: is a

The index of the first occurrence of letter "i" is: 2

Input/Output

Tcl的绝大多数输入/输出是通过puts和gets做到的。Puts命令显示在console上，gets命令从console输入上取得数据，并存储在某个[变量](http://baike.baidu.com/view/296689.htm)中。

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

## 文件句柄

channelID可以理解为c的[文件句柄](http://baike.baidu.com/view/1706628.htm)，varName如果定义，输入值就赋给它，gets返回读入的字节数，否则gets直接返回输入值。

Example 9.1:

puts -nonewline "Enter your name: "

set bytesread \[gets stdin name]

puts "Your name is $name, and it is $bytesread bytes long"

Output: (note that user input is shown in italics)

Enter your name: Shyam

Your name is Shyam, and it is 5 bytes long

Example 9.2:

set f \[open "/tmp/myfile" "w"]

puts $f "We live in Texas. It's already 110 degrees out here."

puts $f "456"

close $f

Output: (none)

Open打开了一个 "/tmp/myfile" 作为channel. 用法是：

open name access

access参数指出打开文件的方式，”w”是读写。这时可以用puts $f把内容写入文件

Example 9.3:

set f \[open "/tmp/myfile" "r"]

set line1 \[gets $f]

set len\_line2 \[gets $f line2]

close $f

puts "line 1: $line1"

puts "line 2: $line2"

puts "Length of line 2: $len\_line2"

Output:

line 1: We live in Texas. It's already 110 degrees out here.

line 2: 456

Length of line 2: 3

这个例子假设已知文件只有两行，如果不是，则需要使用循环，用eof来找到文件尾。

eval

eval命令会把它的参数直接送往[解释器](http://baike.baidu.com/view/592974.htm)。

Example 10.1:

set foo "set a 22"

eval $foo

puts $a

Output:

22

单纯的执行$foo不会成功。

catch

Example 10.2:

set retval \[catch {set f \[open "nosuchfile" "r"]}]

if {$retval == 1} {

puts "An error occured"

}

Output: (this output occurs if there is no file named "nosuchfile" in the current directory).

An error occured

Catch 参数记录一个script的执行情况，如果返回值为1，则执行出错。用来进行错误处理。

* * *

[Go to source web page&gt;&gt;](http://baike.baidu.com/view/459615.htm)

像Perl,Python,Rexx,Tcl,Visual Basic和Unix shells代表了与系统程序设计语言完全不同的编程.脚本语言假设已经存在了一系列由其他语言写成的有用的组件.脚本语言不希望随机地产生请求,他希望主要是把组件接在一起.例如,Tcl和Visual Basic可以被用于在屏幕上安排一系列用户图形控制,而Unix shells scripts被用于把过滤程序集合入管道.脚本语言常用于扩展组件特性,但他们很少用于复杂的算法和数据结构;这些东西常由组件提供.脚本语言有时涉及胶着语言或系统整体语言.

为了简化连接组件的工作,脚本语言被设计为无类型的:所有的东西无论是看起来还是使用起来都是完全一样的,因此他们可以互换.例如,在Tcl或Visual Basic中一个变量可以一会儿处理字符串,一会儿又处理整型.代码和数据也常可互换,因此,可以用一个程序写另一个程序,然后高速执行,脚本语言一般是面向字符的,因为它为许多不同的事物提供了一致的描述.

无类型语言使组件更容易连在一起.在使用时没有优先级限制,并且所有的组件及其值都用统一的方式描述.除此之外,任何组件和值都可以在任何情况下使用;为某一目的而设计的组件可以被用于设计者完全没有预见过的完全不同的目的.例如,在Unix shells中,所有的过滤程序从输入读入字节流,并把字节组成的字符串写入输出;任何两个程序都可以通过把一个的输出连到另一个的输入而把两者联系起来. 下面的shell命令把三个过滤堆在一起来计算选中区域中包含单词"scripting" 的行数:

select | grep scripting | wc

select程序读入当前显示选中的文本并把它输出;grep程序读取输入并把包含"scripting"的行输出;wc程序对输入的行数求和.其中的每个 程序都可以用于许多其他情况来做不同的工作. 系统程序设计语言的强类型本质上阻止重用.类型鼓励编程人员创建包含不相容接口的类型("接口很好,接口越多越好").每个接口需要特别类型的对象,而编译器不允许接口用任何其他类型的对象,即使那样有用.为了使用一个已经存在的接口的新的对象,就必须写转换代码以便在对象的类型和接口期望的类型间进行翻译.这反过来又需要重编译部分或全部分布式二进制形式的应用程序,在普通情况下这是不可能的.为了能看出无类型语言的优点,考虑下面的Tcl命令:

button .b -text Hello! -font {Times 16} -command {puts hello}

这个命令创建了一个新的按钮来显示16点Times字体,当用户敲击控制键时显示一段小的信息.它把六种不同的类型混合成一个单一的状态:一个命令名(button),一个按钮控制(.b),所有权名字(-text, -font, 和-command),简单字符串(Hello! 和hello),包含铅字名(Times)及字点大小(16)的字体名(Times 16)和Tcl脚本(puts hello).Tcl代表所有这些非正式字符串.在这个例子中可以在任何一个命令中为属性

赋值,而未赋值的属性使用给定的缺省值.在这个例子中20个以上的属性是不特别赋值的. 同样的例子在Java中用两种方法执行时需要7行代码.使用C++和微软基本类（MFC）需要三个过程25行代码,在微软基本类中仅仅设臵字体就需要几行代码: CFont \*fontPtr = new CFont(); fontPtr-&gt;CreateFont(16, 0, 0,0,700, 0, 0, 0, ANSI\_CHARSET, OUT\_DEFAULT\_PRECIS,CLIP\_DEFAULT\_PRECIS, DEFAULT\_QUALITY, DEFAULT\_PITCH|FF\_DONTCARE, "Times New Roman"); buttonPtr-&gt;SetFont(fontPtr); 大部分代码是由强类型造成的.为了设臵按钮字体,必须运用SetFont方法,但这个方法必须通过指针传给CFont对象,这反过来需要声明和初始化一个新的对象.为了初始化CFont对象必须唤醒它的CreateFont 方法,但CreateFont有一个需要14个特殊化引数的固定接口.在Tcl中字体(Times铅字,16点)的基本特征不用声明或转换就可以立即使用.另外,Tcl允许在创建按钮的命令中直接包含按钮行为,而C++和Java中需要把它放在单独声明的方法中.这可能看起来脚本语言的无类型特性不能发现错误,但实际上脚本语言和系统程序设计语言一样安全.例如在上面的按钮例子中如果字体大小被臵成非整型字符串,就像xyz,那么就会出现错误.不同的是当一个值被使用时脚本语言在最后一刻进行错误检查,而强类型在编译时发现错误这就避免了运行时的检查.然而提高效率的代价是限制信息如何使用:这导致了更多的代码和更不易改变的程序.

脚本语言和系统程序设计语言的另一个重要不同是脚本语言是被解释而系统程序设计语言是被编译.

脚本语言和系统程序设计语言的另一个重要不同是脚本语言是被解释而系统程序设计语言是被编译.

脚本语言不如系统程序设计语言效率高,部分是因为他们使用解释器而不是编译器,而且因为他们基本组件的选择标准是功能强大和易于使用而不是有效地对应基本硬件.例如,脚本语言经常使用长度可变的字符串,而同样的情况下系统程序设计语言使用对应一个机器字的二进制值;脚本语言经常使用哈希表,而系统程序设计语言使用变址阵列.