0% found this document useful (0 votes)
167 views9 pages

TCL A Universal Scripting Language

This document discusses Tcl, a universal scripting language created by John Ousterhout. Some key points: - Tcl was created to provide a reusable scripting language that could be embedded in applications to provide interactive command languages. It allows applications to be extended with additional features through scripts. - Tcl has a simple syntax similar to shell scripting languages and supports variables, expressions, procedures, conditionals, and access to files and processes. All data is represented as strings for easy access from C. - Applications embed Tcl by generating scripts, parsing them, and extending Tcl's built-in commands through application-specific command procedures implemented in C. This allows new object types and operations to be defined to build

Uploaded by

Yuvaraja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views9 pages

TCL A Universal Scripting Language

This document discusses Tcl, a universal scripting language created by John Ousterhout. Some key points: - Tcl was created to provide a reusable scripting language that could be embedded in applications to provide interactive command languages. It allows applications to be extended with additional features through scripts. - Tcl has a simple syntax similar to shell scripting languages and supports variables, expressions, procedures, conditionals, and access to files and processes. All data is represented as strings for easy access from C. - Applications embed Tcl by generating scripts, parsing them, and extending Tcl's built-in commands through application-specific command procedures implemented in C. This allows new object types and operations to be defined to build

Uploaded by

Yuvaraja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Tcl: A Universal Scripting Language

John Ousterhout
Sun Microsystems Laboratories
[email protected]
http://www.sunlabs.com/~ouster

Introduction

What is a scripting language?


High level (basic units are big).
Most programs are short (extensions, glue).
Dynamic (interpreted).
What is a unversal scripting language?
Single language for many purposes.
Embeddable and extensible.
Benefits:
Easy to learn and use (5-10x faster than C?).
Power: more things programmable, applications work
together.
Active objects: replace data with scripts.

Tcl: A Universal Scripting Language

October 26, 1995, slide 2

Outline

An example:
Tcl: universal scripting language.
Tk: GUI toolkit based on Tcl.
Language rationale:
Unusual design goals (e.g. extensibility).
Key features:
Unstructured (everything's a string).
No grammar.
Quote by default.
Substitutions.

Challenge: raise the level of language design.

Tcl: A Universal Scripting Language

October 26, 1995, slide 3

How I Got Started

Interactive programs need command languages:


Typically redone for each application.
Result: weak, quirky.
emacs and csh powerful, but can't reuse.
Solution: reusable scripting language.
Interpreter is a C library.
Provides basic features: variables, procedures, etc.
Applications extend with additional features.

Tcl: A Universal Scripting Language

October 26, 1995, slide 4

Tcl: Tool Command Language

Simple syntax (similar to sh, C, Lisp):


set a 47
47

Substitutions:
set b $a
set b [expr $a+10]

47
57

Quoting:
set b "a is $a"
a is 47
set b {[expr $a+10]} [expr $a+10]

Tcl: A Universal Scripting Language

October 26, 1995, slide 5

More On The Tcl Language

Rich set of built-in commands:


Variables, associative arrays, lists.
C-like expressions.
Conditionals, looping:
if {$x < 3} {
puts "x is too small"
}

Procedures.
Access to UNIX files, subprocesses.
Only representation is strings:
Easy access from C.
Programs and data interchangeable.

Tcl: A Universal Scripting Language

October 26, 1995, slide 6

Factorial Procedure
proc fac x {
if $x<=1 {return 1}
expr $x*[fac [expr $x-1]]
}
fac 4

24

Tcl: A Universal Scripting Language

October 26, 1995, slide 7

Embedding Tcl In Applications

Application generates scripts.

Tcl parses scripts, passes words


to command procedures.

Application extends built-in


command set:

Tcl

Application
Init

Parser

Command
Loop

Built-In
Commands

Application
Commands

Define new object types in C.


Implement primitive operations
as new Tcl commands.
Build complex features with Tcl
scripts.

Tcl: A Universal Scripting Language

October 26, 1995, slide 8

Extensions
Init

Parser

Command
Loop

Extensions can be developed independently:


Network communication, database access, security, ...
Applications can include combinations of extensions.

Tcl: A Universal Scripting Language

October 26, 1995, slide 9

You might also like