Tcl

Tcl nel Terminale (Jim Tcl): prompt interattivo e script, con liste, dict, regexp, oggetti e file. Scrivi tcl per il prompt, tcl script.tcl per eseguire un file.

versione 0.84 · Licenza: BSD-2-Clause · Sito del progetto

Tcl

A cosa serve

Tcl è un linguaggio di scripting dove tutto è un comando e tutto è una stringa: semplice da imparare, ottimo per automatismi e piccoli strumenti. Questa è Jim Tcl, un Tcl compatto con liste, dict, espressioni regolari, proc, lambda, oggetti (oo), namespace e file. Qui hai il prompt interattivo e l'esecuzione di file .tcl.

Come si usa

Comando Cosa fa
tcl apre il prompt interattivo (.)
tcl script.tcl esegue un file dalla cartella home
tcl script.tcl a b passa argomenti, letti in $argv
tcl -e 'expr {6 * 7}' esegue una riga al volo

Nel prompt ogni riga è un comando e il risultato viene mostrato; un blocco { lasciato aperto continua alla riga dopo:

. expr {6 * 7}
42
. set nomi {anna bruno carla}
. lsort -decreasing $nomi
carla bruno anna
. proc quadrato {x} { expr {$x * $x} }
. quadrato 12
144
. dict set eta anna 30
. dict get $eta anna
30
. foreach i {1 2 3} { puts "riga $i" }

File:

set f [open /nota.txt w]; puts $f "ciao da Tcl"; close $f
set f [open /nota.txt]; puts [gets $f]; close $f

Per uscire: exit, oppure EOF.

Limiti

Niente processi esterni (exec), socket, segnali ed event loop (after, vwait). Gli interi sono a 64 bit (niente numeri enormi: per quelli c'è bc). Memoria disponibile: fino a 8 MB.

Nel Terminale

Tcl

Tcl in the Terminal (Jim Tcl): interactive prompt and scripts, with lists, dicts, regexp, OO and file I/O. Type tcl for the prompt, tcl script.tcl to run a file.

version 0.84 · License: BSD-2-Clause · Project site

Tcl

What it is

Tcl is a scripting language where everything is a command and everything is a string: easy to learn, great for automation and small tools. This is Jim Tcl, a compact Tcl with lists, dicts, regular expressions, proc, lambdas, objects (oo), namespaces and files. You get the interactive prompt and .tcl file execution.

How to use it

Command What it does
tcl opens the interactive prompt (.)
tcl script.tcl runs a file from the home folder
tcl script.tcl a b passes arguments, read from $argv
tcl -e 'expr {6 * 7}' runs one line

At the prompt each line is a command and its result is shown; a { block left open continues on the next line:

. expr {6 * 7}
42
. set names {anna bruno carla}
. lsort -decreasing $names
carla bruno anna
. proc square {x} { expr {$x * $x} }
. square 12
144
. dict set age anna 30
. dict get $age anna
30
. foreach i {1 2 3} { puts "line $i" }

Files:

set f [open /note.txt w]; puts $f "hello from Tcl"; close $f
set f [open /note.txt]; puts [gets $f]; close $f

To quit: exit, or EOF.

Limits

No external processes (exec), sockets, signals or event loop (after, vwait). Integers are 64-bit (no huge numbers: use bc for those). Memory: up to 8 MB.

In the Terminal