수색…


통사론

  • # 유효한 코멘트입니다.
  • # 유효한 {comment}입니다.

코멘트 배치

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

누락 된 대괄호 : 누락 된 대괄호가 주석 오류로 표시됩니다.

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

이것은 중괄호가 적절하게 쌍으로되어 있기 때문에 작동합니다.

인용

Tcl 언어에서는 많은 경우 특별한 따옴표가 필요하지 않습니다.

다음은 유효한 문자열입니다.

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

Tcl 언어는 공백에 단어를 나눕니다. 따라서 공백이있는 모든 리터럴이나 문자열을 따옴표로 묶어야합니다. 문자열을 인용하는 두 가지 방법이 있습니다. 중괄호와 따옴표 포함.

{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