tcl
Tcl Language Constructs
Ricerca…
Sintassi
- # Questo è un commento valido
- # Questo è un valido {commento}
Inserimento di commenti
I commenti in Tcl sono meglio pensati come un altro comando.
Un commento è composto da un # seguito da un numero qualsiasi di caratteri fino alla nuova riga successiva. Un commento può apparire ovunque sia possibile inserire un comando.
# this is a valid comment
proc hello { } {
# the next comment needs the ; before it to indicate a new command is
# being started.
puts "hello world" ; # this is valid
puts "dlrow olleh" # this is not a valid comment
# the comment below appears in the middle of a string.
# is is not valid.
set hw {
hello ; # this is not a valid comment
world
}
gets stdin inputfromuser
switch inputfromuser {
# this is not a valid comment.
# switch expects a word to be here.
go {
# this is valid. The switch on 'go' contains a list of commands
hello
}
stop {
exit
}
}
}
Bretelle nei commenti
A causa del modo in cui il parser del linguaggio Tcl funziona, le parentesi nel codice devono essere correttamente abbinate. Ciò include le parentesi nei commenti.
proc hw {} {
# this { code will fail
puts {hello world}
}
Una parentesi chiusa mancante: verrà lanciata una possibile parentesi squilibrata nell'errore di commento .
proc hw {} {
# this { comment } has matching braces.
puts {hello world}
}
Funzionerà come le parentesi sono abbinate correttamente.
citando
Nel linguaggio Tcl in molti casi, non è necessario alcun preventivo particolare.
Queste sono stringhe valide:
abc123
4.56e10
my^variable-for.my%use
Il linguaggio Tcl divide le parole in spazi vuoti, quindi dovrebbero essere citati tutti i letterali o le stringhe con spazi bianchi. Ci sono due modi per citare le stringhe. Con bretelle e con virgolette.
{hello world}
"hello world"
Quando si citano le parentesi, non vengono eseguite sostituzioni. Le parentesi graffe incorporate possono essere sfuggite con una barra rovesciata, ma si noti che la barra rovesciata fa parte della stringa.
% puts {\{ \}}
\{ \}
% puts [string length {\{ \}}]
5
% puts {hello [world]}
hello [world]
% set alpha abc123
abc123
% puts {$alpha}
$alpha
Quando si citano virgolette doppie, il comando, il backslash e le sostituzioni di variabili vengono elaborati.
% puts "hello [world]"
invalid command name "world"
% proc world {} { return my-world }
% puts "hello [world]"
hello my-world
% puts "hello\tworld"
hello world
% set alpha abc123
abc123
% puts "$alpha"
abc123
% puts "\{ \}"
{ }