Category:Tcl

From Rosetta Code
Revision as of 23:28, 30 August 2009 by rosettacode>Dkf (→‎Language Syntax: More detail on effective syntax)
Language
Tcl
This programming language may be used to instruct a computer to perform a task.
Official website
Execution method: Compiled (bytecode)
Garbage collected: Yes
Parameter passing methods: By value
Type safety: Safe
Type strength: Weak
Type compatibility: Duck
Type expression: Implicit
Type checking: Dynamic
Lang tag(s): tcl
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using Tcl.
Try this language on Codepad.

Tcl (short for Tool Command Language) is a scripting language with very simple syntax, dynamic typing, automatic storage allocation and garbage collection and native Unicode support. Tcl is often combined with the Tk library. As a result, it is often referred to as Tcl/Tk.

Tcl is known to be supported under a variety of popular operating systems, including UNIX, Linux, BSD, Windows, WinCE, PocketPC, Mac OS X and BeOS. Tcl is distributed under the BSD License.

The Tcl language has been implemented in multiple lower-level languages. The most common one is libtcl, written in C, which is the engine used to power tclsh and wish, but others exist. Notably, these include Jacl and Eagle, which implement Tcl in Java and C# respectively.

Its creator, John Ousterhout, wrote about it:

“I got the idea for Tcl while on sabbatical leave at DEC's Western Research Laboratory in the fall of 1987. I started actually implementing it when I got back to Berkeley in the spring of 1988; by summer of that year it was in use in some internal applications of ours, but there was no Tk. The first external releases of Tcl were in 1989, I believe. I started implementing Tk in 1989, and the first release of Tk was in 1991.”

The principal pre-built distributions of Tcl are all based on libtcl; the main ones are ActiveTcl from ActiveState, and tclkit from Equi4 Software et al. Older versions of the language are distributed as part of Apple's OSX and all Linux distributions.

Language Syntax

Grammar

Note that this is a simplified language grammar, and it is normal to think of the language at a higher level where these differences don't show.

script     ::= command? ((\n|;) script )
command    ::=#” characters “\n/* comment */
             | word ( space word )*       /* sequence of space-separated words;
                                           * first is command name */
             |                            /* empty */
word       ::={*}?{” characters “}/* braces must be balanced */
             |{*}?"” charSubsts “"/* double-quotes must be balanced */
             |{*}? charSubsts
charSubsts ::=[” script “]” charSubsts? /* brackets must be balanced */
             |$” varName charSubsts?
             |${” varName “}” charSubsts?
             |\\” escapeSequence charSubsts?
             | ordinaryChar charSubsts?

The syntax of the language is defined more exactly in the Tcl(n) manual page.

Conceptual Command Syntax

Though formally not part of the language syntax, the syntactic style of the language's standard commands mostly follow a few basic syntactic principles:

  • Commands are variadic, and frequently accept arbitrary numbers of arguments.
  • Commands that take options will prefix the option name with a single ASCII hyphen, “-”, and if a value parameter to the option is required, that parameter will be in a subsequent argument to the option name.
  • Option names are not single character long strings after removing the hyphen (except in rare cases) and getopt-style argument combination is never supported.
  • Commands perform callbacks by evaluating a caller-provided Tcl script.
    • During-execution callback scripts are evaluated in the context of their caller.
    • After-execution callback scripts are evaluated in the global scope.
  • Commands cannot discover how their arguments were quoted.

Language Semantics

Value Model

Tcl's value model operates on two levels.

  • Classically, it is defined purely on unmodifiable strings over a language of unencoded UNICODE characters.
  • Practically, values are polymorphic and hold a cache of the last type-interpretation that they were used with, together with an optional UTF-8 string representation. They are reference-counted and are not modifiable (unless the code in question holds the only reference, which is a significant efficiency gain; if the value is shared, it is shallow-copied upon modification). Although only reference-counted, they are effectively garbage-collected since circular data structures cannot be constructed (performing such construction requires holding two references to the same object, which forces a copy to be taken and breaks the reference loop). The net effect of this is just like the UNICODE string classical model, except much faster.

The language supports the following basic types, together with many defined by extension packages:

  • Unicode strings
  • Binary strings
  • Integers of unbounded width
  • Double-precision IEEE floats
  • Booleans
  • Lists of values
  • Dictionaries mapping values to values
  • Assorted "cache" types used to boost performance:
    • Command handles (several types)
    • Variable handles (several types)
    • Compiled regular expressions
    • Compiled scripts (several types)
    • etc.

Note that all variables can hold values of any type; the language does not impose type constraints on variables at all. However, it is possible to use variable traces to enforce a type constraint if so desired.

External Links

Subcategories

This category has the following 4 subcategories, out of 4 total.

Pages in category "Tcl"

The following 200 pages are in this category, out of 983 total.

(previous page) (next page)

C

(previous page) (next page)