サーチ…


構文

  • #これは有効なコメントです
  • #これは有効な{コメント}です

コメントを配置する

Tclのコメントは別のコマンドと考えるのが一番です。
コメントは#それに続く改行までの任意の数の文字で構成されます。コマンドを置くことができるところであれば、コメントを表示することができます。

# 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
     }
  }
}

コメント中の括弧

Tcl言語パーサが動作する方法のために、コード内の中カッコが適切に一致していなければなりません。これにはコメントの中カッコが含まれます。

proc hw {} { 
   # this { code will fail
   puts {hello world}
}

close braceがありません:コメントのエラーでアンバランスなブレースが発生する可能性があります。

proc hw {} {
  # this { comment } has matching braces.
  puts {hello world}
}

中括弧が適切にペア設定されているので、これは機能します。

引用

多くの場合、Tcl言語では特別な引用は必要ありません。

これらは有効な文字列です。

abc123
4.56e10
my^variable-for.my%use

Tcl言語は空白上の単語を分割するので、空白を持つ任意のリテラルまたは文字列を引用符で囲む必要があります。文字列を引用するには2つの方法があります。中括弧と二重引用符で囲みます。

{hello world}
"hello world"

中括弧で引用すると、置換は行われません。埋め込み中括弧はバックスラッシュでエスケープすることができますが、バックスラッシュは文字列の一部です。

% puts {\{ \}}
\{ \}
% puts [string length {\{ \}}]
5
% puts {hello [world]}
hello [world]
% set alpha abc123
abc123
% puts {$alpha}
$alpha

二重引用符でクォートすると、コマンド、バックスラッシュ、および変数の置換が処理されます。

% 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 "\{ \}"
{ }


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow