Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/TCL+for+beginners?V=64
QUERY_STRINGV=64
CONTENT_TYPE
DOCUMENT_URI/revision/TCL+for+beginners
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.100.40
REMOTE_PORT55580
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.16.69.143
HTTP_CF_RAY88085ae4ec8989fa-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_CF_CONNECTING_IP3.16.69.143
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {TCL for beginners} '''Tcl\ for\ Beginners''',\ \ is\ another\ \[Beginning\ Tcl%|%introduction\]\ to\ \[Tcl\]\n\n<<TOC>>\n\n**\ See\ Also\ **\n\n\ \ \ \[Dodekalogue\]:\ \ \ \n\n\ \ \ `\[foreach\]`:\ \ \ \ A\ simple\ and\ powerful\ command\ that\ is\ used\ extremely\ often\ \n\n\ \ \ \[gotcha\]:\ \ \ \n\n\ \ \ \[Why\ can\ I\ not\ place\ unmatched\ braces\ in\ Tcl\ comments\]:\ \ \ \n\n\n\n**\ Tcl\ is\ All\ about\ Commands\ **\n\nTcl\ works\ by\ processing\ commands.\ \ In\ this\ regard,\ it's\ similar\ to\ an\ operating\nsystem\ shell\ like\ \[MS-DOS%|%DOS\]\ or\ \[bash\].\ \ Each\ line\ of\ a\ Tcl\ script\ is\ a\ncommand,\ and\ the\ first\ word\ of\ each\ line\ is\ the\ name\ of\ the\ command,\ and\ any\nother\ words\ are\ arguments\ for\ the\ command.\ \ Tcl\ looks\ up\ the\ code\ associated\nwith\ that\ name\ and\ invokes\ it.\ \n\n\nIn\ DOS,\ for\ example,\ to\ list\ the\ contents\ of\ a\ directory\ you\ would\ type:\n\n======none\ndir\ c:\\path\\to\\folder\n======\n\nin\ Tcl\ you\ would\ write:\n\n======\nglob\ /path/to/folder/*\n======\n\n`\[glob\]`\ is\ a\ Tcl\ command,\ and\ has\ a\ purpose\ analogus\ to\ the\ '''dir'''\ command\ in\n\[MS-DOS\].\n\n\n\n**\ Commands\ are\ Made\ of\ Words\ **\n\nAnother\ useful\ command\ is\ `\[puts\]`,\ which,\ like\ the\ ''echo''\ command\ in\ \[MS-DOS\],\nprints\ things\ out\ on\ the\ screen:\n\n======\nputs\ Hello\n======\n\nA\ mnemonic\ device\ for\ `\[puts\]`\ is\ '''put'''\ '''s'''tring.\n\nThere\ are\ commands\ that\ interpret\ words\ as\ numbers\ in\ order\ to\ get\ some\ math\ndone,\ but\ it's\ up\ to\ each\ individual\ command\ to\ decide\ how\ it\ wants\ to\ treat\nany\ particular\ word.\ \ Tcl\ makes\ no\ distinction.\n\n\n\n**\ Escaping\ Interpretation\ **\n\nIn\n\n======\nputs\ Hello\n======\n\n,\ there\ are\ no\ quotes\ around\ `Hello`.\ \ No\ quotes\ are\ needed\nin\ Tcl\ because\ all\ words,\ including\ the\ names\ of\ commands,\ are\ just\ strings.\nIn\ fact,\ in\ Tcl,\ \[everything\ is\ a\ string%|%every\ value\ is\ a\ string\].\ \ Because\ of\nthis,\ quotes\ are\ not\ used\ to\ signify\ that\ something\ is\ a\ string\ -\ that's\nalready\ a\ given.\ \ Instead,\ quotes,\ braces,\ and\ backslashes\ are\ used\ to\ take\naway\ the\ special\ meaning\ that\ some\ characters\ have.\ \ Whitespace\ normally\ has\ a\nspecial\ meaning\ to\ Tcl,\ since\ it\ separates\ words\ in\ a\ command.\ \ To\ include\ \nwhitespace\ characters\ as\ part\ of\ a\ value,\ use\ backslash,\ braces,\ quotes\ to\ tell\ Tcl\ not\ to\ see\ that\ whitespace\ as\ a\ word\ delimiter.\n\n`\[set\]`\ only\ takes\ two\ arguments.\ \ Therefore,\ this\ code\n\n======\nset\ foo\ good\ afternoon\n======\n\nwill\ result\ in\n\n======none\nerror:\ wrong\ #\ args:\ should\ be\ \"set\ varName\ ?newValue?\"\n======\n\nWe\ need\ to\ tell\ Tcl\ that\ the\ space\ between\ `good`\ and\ `afternoon`\ is\ part\ of\nthe\ value.\ \ Here\ is\ an\ example\ of\ doing\ that\ using\ backslash,\ braces,\ and\nquotes,\ repectively:\n\n======\nset\ foo\ good\\\ afternoon\ \nset\ foo\ \{good\ afternoon\}\nset\ foo\ \"good\ afternoon\"\n======\n\n\nBraces\ and\ quotes\ only\ have\ this\ special\ meaning\ when\ they\ completely\ enclose\ a\ word\ of\ a\ Tcl\ command.\ \ In\ the\ middle\ of\ a\ word,\ they\ are\ just\ regular\ characters.\n\n======\nputs\ This\"is\{a\"single\}\"value\n======\n\nNot\ even\ newlines\ can\ stop\ braces:\n\n======\nputs\ \{This\ is\ a\ whole\n\ \ \ paragraph\ inside\ braces.\ \ Braces\ just\n\ \ \ don't\ quit\ until\ the\ matching\ closing\ brace\n\ \ \ is\ found.\ \ Backslashed\ \\\}\ braces\ don't\ close\ it\ Off.\ \ Neither\n\ \ \ do\ \"Quotes\".\ \ \{other\ matching\ braces\}\ are\ OK,\ too.\ \ But\ finally,\n\ \ \ we\ get\ to\ the\ closing\ brace.\n\}\n======\n\n\n\n**\ Using\ Variables\ **\n\nUse\ `\[set\]`\ to\ set\ the\ value\ of\ a\ variable:\n\n\n======\nset\ greeting\ Hello\n======\n\nTo\ get\ the\ value\ back\ out\ of\ a\ variable\ use\ a\ dollar\ sign.\ \ For\ example,\ to\nprint\ `Hello`:\n\n======\nputs\ \$greeting\n======\n\nThis\ works\ even\ if\ there\ is\ white\ space\ in\ the\ greeting:\n\n======\nset\ greeting\ \{Hello\ There\}\nputs\ \$greeting\n======\n\nThat's\ because\ Tcl\ substitutes\ the\ entire\ value\ of\ the\ variable\ into\ the\ the\nspot\ where\ `\$greeting`\ was.\n\n\n\n**\ Command\ Substitution\ **\n\nVariable\ substitution\ isn't\ the\ only\ substitution\ game\ in\ town.\ \ There's\ also\ncommand\ substitution.\ \ This\ is\ done\ with\ square\ brackets.\ \ To\ print\ `Hello`\ to\nthe\ screen\ using\ command\ substitution:\n\n======\nset\ greeting\ Hello\nputs\ \[set\ greeting\]\n======\n\nWhen\ `\[set\]`\ only\ gets\ one\ argument\ instead\ of\ two,\ it\ returns\ the\nvalue\ of\ the\ variable\ instead\ of\ setting\ it.\n\nNotice\ also\ that\ we\ just\ used\ the\ name\ of\ the\ variable\ without\ prepending\ a\ndollar\ sign\ to\ it.\ \ If\ we\ had\ prepended\ the\ dollar\ sign,\ it\ would\ have\ been\nequivalent\ to\ typing\ `set\ Hello`,\ in\ which\ case\ `\[set\]`\ would\ have\ gone\ to\nfind\ the\ value\ of\ the\ variable\ named,\ \"Hello\",\ failed\ to\ find\ it,\ and\ returned\nan\ error.\n\nKnowing\ that,\ you\ should\ be\ able\ to\ make\ sense\ of\ the\ following\ code:\n\n======\nSet\ Hello\ Howdy\nset\ greeting\ Hello\nputs\ \[set\ \$greeting\]\n======\n\nWhat\ will\ be\ printed\ to\ the\ screen?\ \ That's\ right:\n\n======none\nHowdy\n======\n\n'''Extra\ Credit'''\ (not\ really\ a\ beginner\ thing):\n\n======\nputs\ \[expr\ \$\$greeting\]\n======\n\nWhat\ will\ be\ printed?\ \ Yes,\ once\ again,\ it's\n\n\n======none\nHowdy\n======\n\nWhy?\ \ Hint:\ what\ does\ `\[\[puts\ \$\$\]`\ do?\n\n----\n\n\[Clif\ Flynt\]:\ When\ I'm\ teaching\ a\ class,\ I\ point\ out\ that\n\n======\nset\ set\ set\n======\n\nis\ a\ valid\ command,\ and\ that\n\n======\nset\ x\ set\nset\ y\ a\nset\ z\ b\n\$x\ \$y\ \$z\n======\n\nis\ a\ valid\ Tcl\ command\ to\ assign\ the\ value\ b\ to\ variable\ a.\ Looking\ at\ this\nmakes\ the\ students\ stop\ and\ think.\ And\ stare\ at\ me\ like\ I'm\ crazy.\n\n\n\n**\ Commenting\ Code\ **\n\nSometimes,\ particularly\ when\ we\ think\ we're\ doing\ something\ really\ clever,\ we\nwant\ to\ add\ comments\ to\ our\ code\ so\ that\ other\ humans\ can\ make\ more\ sense\ of\nit.\ \ To\ do\ this\ in\ Tcl,\ we\ use\ the\ pound\ character,\ but\ only\ at\ the\ beginning\nof\ a\ command:\n\n\n======\n#puts\ \{This\ line\ won't\ ever\ happen,\ because\ it's\ commented\}\nputs\ Whew!\n======\n\n\n\n**\ Using\ Double\ Quotes\ **\ \n\nBraces\ inhibit\ variable\ substitution,\ command\ substitution,\ and\ most\ backslash\nsubstitution:\n\n======\nset\ name\ John\n\n#warning\ -\ This\ next\ line\ won't\ substitute\ in\ John.\ \ It\ just\ prints\ exactly\n#what\ is\ in\ the\ braces,\ including\ the\ \$.\nputs\ \{Hello\ \$name\}\n======\n\n\nWhen\ we\ want\ those\ substitutions,\ but\ we\ also\ need\ white\ space\ to\ just\ be\ white\nspace,\ we\ can\ use\ double\ quotes\ instead\ of\ braces.\ \ Double\ quotes\ have\ the\ same\npurpose\ as\ braces,\ but\ also\ allow\ all\ substitutions:\n\n======\nset\ name\ John\nset\ greeting\ \"Hello,\ \$name!\ \ Hello\ again,\ \[set\ name\]!\"\ \n======\n\n\nAs\ with\ braces,\ newlines\ inside\ quotes\ are\ just\ newlines:\n\n======\nputs\ \"In\ double\ quotes,\ newlines\n\ \ \ \ are\ \ just\ newlines.\ \ If\ you\ escape\ a\ newline,\ \\\n\ \ \ \ it\ disappears\ entirely.\ \ Braces\ are\ just\ \{braces\},\n\ \ \ \ and\ other\ \\\"double\ quotes\\\"\ can\ be\ escaped.\ \[\n\ \ \ \ \ \ \ \ set\ value\ \{Command\ Substitution,\ which\ should\ really\ be\ called\n\ \ \ \ \ \ \ \ \"script\ substitution\"\}\n\ \ \ \ \ \ \ \ set\ value\n\ \ \ \ \],\ is\ also\ not\ a\ problem\ at\ all.\ \ Notice\ that\ there\ were\ multiple\ commands\n\ \ \ \ in\ that\ last\ command\ substitution,\ and\ the\ value\ of\ the\ last\ command\ is\ what\n\ \ \ \ actually\ takes\ the\ place\ of\ the\ entire\ command\ substitusion.\ \ It\ doesn't\n\ \ \ \ hurt\ to\ escape\ \\\{braces\\\},\ but\ it\ isn't\ necessary,\ either.\ \ Escaping\ regular\ \\letters\n\ \ \ \ doen't\ do\ anything\ at\ all\ to\ them.\ \ An\ \\a\ is\ just\ an\ a.\ \ Finally,\ we\ get\n\ \ \ \ to\ the\ closing\ quote.\"\n\"\n======\n\n\n\n**\ Using\ Backslashes\ **\n\n\nIn\ addition\ to\ variable\ and\ command\ substitution,\ there\ is\ on\ other\ substituion\ndevice:\ \ Backslashes.\ \ They\ are\ used\ in\ Tcl\ in\ a\ manner\ very\ similar\ to\ that\ of\n\[C\]/\[C++\].\ The\ following\ are\ backslash\ substitutions\ understood\ by\ Tcl:\n\n\ \ \ '''`\\a`''':\ \ \ Audible\ alert\ (bell)\ (0x7)\n\ \ \ '''`\\b`''':\ \ \ Backspace\ (0x8)\n\ \ \ '''`\\f`''':\ \ \ Form\ feed\ (0xc)\ \n\ \ \ '''`\\n`''':\ \ \ Newline,\ LF\ (0xa)\n\ \ \ '''`\\r`''':\ \ \ Carriage-return,\ CR\ (0xd)\n\ \ \ '''`\\t`''':\ \ \ Tab\ (0x9)\n\ \ \ '''`\\v`''':\ \ \ Vertical\ tab\ (0xb)\n\nThe\ additional\ backslash\ sequences,\ '''`\\x`'''\ and\ '''`\\u`''',\ are\ some\ndocumented\ in\ the\ \[Dodekalogue\].\ \ They\ point\ to\ the\ fact\ that\ Tcl\ is\ not\nrestricted\ to\ 8-bit\ characters,\ a\ limitation\ of\ some\ other\ languages.\n\nIf\ a\ `\\`\ is\ followed\ by\ up\ to\ 3\ digits\ of\ numbers,\ than\ it\ is\ treated\ as\ an\noctal\ value\ for\ a\ character\ and\ the\ actual\ character\ is\ then\ substituted\ in\ its\nplace.\n\nAny\ other\ character\ following\ a\ `\\`\ is\ replace\ with\ itself.\ This\ is\ an\ 'escape'\nmechanism\ that\ enables\ you\ to\ make\ character\ just\ be\ themselves\ in\ places\ where\nTcl\ would\ normally\ assign\ some\ special\ meaning\ to\ them:\n\n======\nputs\ \"what\ do\ we\ mean\ when\ we\ say,\ \\\"word\\\"?\"\n======\n\nIf\ a\ backslash\ '''\\'''\ appears\ at\ the\ end\ of\ a\ line,\ then\ that\ line\ continues\non\ to\ the\ next\ line:\n\n======\nputs\ \\\n\ \ \"Continued\ from\ the\ line\ above\"\n======\n\nThis\ is\ to\ allow\ a\ long\ line\ of\ code\ to\ be\ split\ into\ multiple\ lines\ if\ you\ run\nout\ of\ space\ in\ your\ text\ editor.\n\n\n\n**\ Word\ Expansion\ **\n\nSometimes\ we\ need\ a\ way\ to\ tell\ Tcl\ to\ consider\ each\ word\ within\ a\ word\ to\ be\nan\ additional\ argument\ to\ a\ command.\ \ For\ example,\ if\ we\ have\ a\ variable\ that\ncontains\ two\ words:\n\n======\nset\ attribute\ \{name\ Bob\}\n======\n\nThe\ following\ would\ result\ in\ a\ four-word\ command,\ including\ the\ name\ of\ the\ncommand:\n\n======\nformat\ \{%s:\ %s\}\ \{*\}\$attribute\n======\n\nThis\ is\ called\ \"word\ expansion\".\n\n\n**\ It's\ really\ All\ about\ Commands\ **\n\nThe\ few\ rules\ that\ have\ just\ been\ described\ constitute\ the\ entirety\ of\ the\ Tcl\nlanguage.\ \ Really!\ \ That's\ it.\ \ There's\ nothing\ more.\ \ The\ description\ above\ is\na\ complete\ description\ of\ the\ Tcl\ language.\ \ There\ doesn't\ need\ to\ be\ anything\nmore\ because\ those\ rules\ are\ entirely\ sufficient\ to\ create\ every\ other\nprogramming\ facility\ that\ exists\ in\ Tcl.\n\nThe\ only\ thing\ you\ will\ ever\ do\ in\ Tcl\ code\ is\ form\ commands.\ \ There\ are\ no\n\[control\ structure%|%control\ structures\]\ in\ \ the\ syntax\ because\ control\ flow\ can\nbe,\ and\ is,\ implemented\ as\ commands.\ \ That's\ why\ Tcl\ really\ is\ all\ about\ the\ncommands.\ \ There\ are\ two\ types\ of\ commands\ which\ may\ be\ considered\ fundamental:\ncommands\ that\ create\ new\ commands,\ i.e.,\ `\[proc\]`,\ and\ commands\ that\nimplement\ conditional\ constructs,\ i.e.,\ `\[if\]`.\n\n\n\n**\ Creating\ New\ Commmands\ **\n\n`\[proc\]`\ is\ used\ to\ create\ new\ commands.\n\n======\nproc\ greet\ \{\}\ \{\n\ \ \ \ puts\ Hello!\n\}\n======Commands\ that\ have\ been\ created\ this\ way\ are\ called\ procedures.\n\nTo\ create\ a\ procedure\ that\ takes\ an\ argument:\n\n======\nproc\ greet\ name\ \{\n\ \ \ \ puts\ \"greeting,\ \$name!\"\n\}\n======\n\nTo\ create\ a\ procedure\ that\ takes\ multiple\ arguments:\n\n======\nproc\ greet\ \{first\ last\}\ \{\n\ \ \ \ puts\ \"hello,\ \$first\ \$last!\"\n\}\n======\n\nSince\ `\[proc\]`\ interprets\ its\ second\ argument\ as\ a\ list,\ the\ following\ works\ as\ well,\ but\ is\ not\ common:\n\n======\nproc\ greet\ \[list\ first\ last\]\ \{\n\ \ \ \ puts\ \"hello,\ \$first\ \$last!\"\n\}\n======\n\nThe\ last\ command\ within\ a\ procedure\ is\ returned\ as\ the\ value\ of\ a\ procedure.\n\n\n======\nproc\ combine\ \{part1\ part2\}\ \{\n\ \ \ \ set\ result\ \$part1\$part2\n\}\ncombine\ hel\ lo\n======\n\nThe\ result\ is:\n\n======none\nhello\n======\n\n`\[return\]`\ can\ be\ used\ to\ be\ more\ explicit.\ \ The\ following\ example\ has\ the\nsame\ result\ as\ the\ previous\ one.\n\n======\nproc\ combine\ \{part1\ part2\}\ \{\n\ \ \ \ return\ \$part1\$part2\n\}\ncombine\ hel\ lo\n======\n\nThere's\ a\ special\ trick\ to\ creating\ a\ procedure\ that\ takes\ a\ variable\ number\ of\narguments.\ \ If\ the\ last\ name\ in\ the\ list\ of\ arguments\ is\ `args`,\nthe\ new\ procedure\ can\ be\ called\ with\ any\ number\ of\ args,\ and\ within\ the\nprocedure,\ \$args\ will\ be\ a\ list\ of\ the\ extra\ arguments:\n\n======\nproc\ greet\ \{greeting\ args\}\ \{\n\ \ \ \ foreach\ name\ \$args\ \{\n\ \ \ \ \ \ \ \ puts\ \"\$greeting,\ \$name!\"\n\ \ \ \ \}\n\}\n======\n\nTo\ create\ a\ procedure\ that\ can\ be\ invoked\ with\ any\ number\ of\ arguments,\ or\ none\ at\ all:\n\n======\nproc\ count\ args\ \{\n\ \ \ \ set\ length\ \[llength\ \$args\]\n\ \ \ \ if\ \{\$length\ ==\ 0\}\ \{\n\ \ \ \ \ \ \ \ puts\ \"I\ was\ invoked\ with\ no\ arguments\"\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ puts\ \"I\ was\ invoked\ with\ \$length\ arguments\"\n\ \ \ \ \}\n\}\n======\n\nAnd\ it\ works\ like\ that:\n\n======\n%\ count\nI\ was\ invoked\ with\ no\ arguments\n%\ count\ a\nI\ was\ invoked\ with\ 1\ arguments\n%\ count\ a\ b\nI\ was\ invoked\ with\ 2\ arguments\n======\n\n\n**\ Conditional\ Constructs\ **\n\n\n`\[if\]`,\ a\ necessary\ construct\ in\ any\ language,\ in\ Tcl\ is\ just\ another\ncommand.\ \ It\ takes\ a\ word\ that\ serves\ as\ the\ condition,\ and\ another\ word\ that\nserves\ as\ the\ script\ to\ run\ in\ the\ event\ that\ the\ criteria\ is\ true:\n\n\n======\nif\ \{1\}\ \{\n\ \ \ \ puts\ \"1\ is\ always\ true!\"\n\}\n======\n\nNotice\ that\ `1`\ is\ braced,\ even\ though\ it\ wasn't\ strictly\ necessary.\ \ Why?\ \ To\nadvocate\ \[Brace\ your\ expr-essions%|%good\ programming\ habits\].\ \ Until\ you\ learn\nenought\ to\ know\ exactly\ when\ not\ to,\ you\ should\ '''always'''\ \[Brace\ your\nexpr-essions%|%brace\ your\ expressions\].\n\n\nHere's\ another\ example:\n\n======\nif\ \{0\}\ \ \{\n\ \ \ \ Anything\ at\ all\ can\ go\ here,\n\ \ \ \ even\ syntactically-invalid\\\{\n\ \ \ \ stuff,\ because\ Tcl\ will\ not\ attempt\n\ \ \ \ to\ evaluate\ this\ word,\ as\ the\ condition\ is\ false.\n\}\n======\n\n\n\n**\ What\ is\ a\ \[list\]?\ **\n\nThe\ Tcl\ \[Dodekalogue%|%language\ specification\]\ doesn't\ have\ anything\ to\ say\nabout\ \[list%|%lists\],\ except\ that\ some\ command\ might\ interpret\ words\ passed\ to\ them\ as\nvarious\ things,\ including\ possibly\ lists.\ \ It\ does\ specify,\ however,\ that\ a\nscript\ is\ a\ string,\ and\ can\ be\ broken\ down\ into\ commands,\ which\ therefore\ must\ also\nbe\ strings.\ \ Commands,\ in\ turn,\ are\ composed\ of\ words.\ \ This\ strongly\ implies\nthat\ the\ syntax\ of\ a\ command\ must\ be\ adequate\ to\ express\ a\ list.\ \ The\ \nbuilt-in\ `\[list\]`\ commands\ of\ Tcl\ accept\ a\ word\ as\ a\ list\ if\ and\ only\nif\ the\ word\ in\ turn\ can\ be\ parsed\ as\ a\ Tcl\ command.\ \ In\nother\ words,\ a\ list\ is\ a\ string\ that\ could\ be\ interpreted\ as\ a\ command.\n\n======\nset\ a\ \"A\ B\ C\"\nlindex\ \$a\ 0\n======\n\nThe\ above\ commands\ return\ :\n\n======none\nA\ B\ C\nA\n======\n\nHowever,\ not\ every\ string\ that\ can\ be\ interpreted\ as\ a\ command\ is\ a\ list.\n\n======\nset\ command\ \{list\ \{*\}\{one\ two\ three\}\}\nlindex\ \$command\ 0\ \;#\ ->\ error:\ list\ element\ in\ braces\ followed\ by\ \"\{one\"\ instead\ of\ space\n======\n\nThe\ meaning\ of\ `\{*\}`\ is\ discussed\ later.\n\n\n`\[lindex\]`\ returns\ the\ list\ element,\ located\ at\ the\ given\ index.\ Indices\nstart\ at\ `0`.\n\n======\nset\ a\ \{A\ B\ C\}\nlindex\ \$a\ 1\n======\n\nresult:\n\n======\nB\n======\n\nIt's\ possible\ for\ a\ list\ to\ contain\ another\ list:\n\n\n======\nset\ a\ \"A\ \{B\ C\}\ D\"\nlindex\ \$a\ 1\n======\n\nresult:\n\n======none\nA\ \{B\ C\}\ D\nB\ C\n======\n\nRemember\ that\ not\ all\ strings\ are\ lists.\n\nAlthough\ `\[split\]`\ can\ be\ used\ to\ convert\ any\ string\ into\ a\ list\ of\ words,\nthat\ doesn't\ mean\ that\ any\ value\ given\ to\ `\[split\]`\ is\ a\ well-formed\nlist.\n\n\n\n**\ DO\ **\n\n\ \ \ *\ Do\ write\ lots\ of\ comments\ in\ your\ code\ about\ what\ your\ code\ does,\ what\ you\ tried\ that\ didn't\ work\ (and\ why,\ if\ known).\n\ \ \ *\ Do\ study\ the\ documentation\ and\ others'\ code\ to\ understand\ 'upvar',\ 'uplevel'.\n\n\ \ \ *\ Learn\ how\ to\ use\ `\[exec\]`\ so\ that\ you\ can\ start\ using\ Tcl\ to\ drive\ external\ programs\n\n\n**\ DON'T\ **\n\n\ \ \ *\ Don't\ have\ unescaped\ unmatched\ brackets\ ANYWHERE,\ including\ comments.\ \ Use\ a\ text\ editor\ that\ helps\ you\ by\ showing\ bracket\ matching.\ \ \n\n\n**\ Getting\ Stuff\ Done\ \ **\n\n\ \ \ *\ \[tcllib\]\ is\ full\ of\ useful\ code.\ Try\ to\ use\ it\ as\ much\ as\ possible,\ a\ wide\ use\ of\ \[tcllib\]\ really\ saves\ time,\ and\ it\ is\ frequently\ updated.\n\n\ \ \ *\ If\ you\ need\ speed,\ be\ aware\ that\ Tcl\ can\ be\ extended\ easily\ (using\ \[C\],\[C++\]...).\ Avoid\ writing\ your\ own\ extensions\ if\ existing\ ones\ can\ do\ the\ job.\n\n\ \ \ *\ Do\ split\ your\ code\ into\ different\ \[namespace\]s\ (and\ files)\ when\ it\ overcomes\ ca.\ a\ thousand\ lines.\n\n\n\n<<categories>>\ Tutorial regexp2} CALL {my render {TCL for beginners} '''Tcl\ for\ Beginners''',\ \ is\ another\ \[Beginning\ Tcl%|%introduction\]\ to\ \[Tcl\]\n\n<<TOC>>\n\n**\ See\ Also\ **\n\n\ \ \ \[Dodekalogue\]:\ \ \ \n\n\ \ \ `\[foreach\]`:\ \ \ \ A\ simple\ and\ powerful\ command\ that\ is\ used\ extremely\ often\ \n\n\ \ \ \[gotcha\]:\ \ \ \n\n\ \ \ \[Why\ can\ I\ not\ place\ unmatched\ braces\ in\ Tcl\ comments\]:\ \ \ \n\n\n\n**\ Tcl\ is\ All\ about\ Commands\ **\n\nTcl\ works\ by\ processing\ commands.\ \ In\ this\ regard,\ it's\ similar\ to\ an\ operating\nsystem\ shell\ like\ \[MS-DOS%|%DOS\]\ or\ \[bash\].\ \ Each\ line\ of\ a\ Tcl\ script\ is\ a\ncommand,\ and\ the\ first\ word\ of\ each\ line\ is\ the\ name\ of\ the\ command,\ and\ any\nother\ words\ are\ arguments\ for\ the\ command.\ \ Tcl\ looks\ up\ the\ code\ associated\nwith\ that\ name\ and\ invokes\ it.\ \n\n\nIn\ DOS,\ for\ example,\ to\ list\ the\ contents\ of\ a\ directory\ you\ would\ type:\n\n======none\ndir\ c:\\path\\to\\folder\n======\n\nin\ Tcl\ you\ would\ write:\n\n======\nglob\ /path/to/folder/*\n======\n\n`\[glob\]`\ is\ a\ Tcl\ command,\ and\ has\ a\ purpose\ analogus\ to\ the\ '''dir'''\ command\ in\n\[MS-DOS\].\n\n\n\n**\ Commands\ are\ Made\ of\ Words\ **\n\nAnother\ useful\ command\ is\ `\[puts\]`,\ which,\ like\ the\ ''echo''\ command\ in\ \[MS-DOS\],\nprints\ things\ out\ on\ the\ screen:\n\n======\nputs\ Hello\n======\n\nA\ mnemonic\ device\ for\ `\[puts\]`\ is\ '''put'''\ '''s'''tring.\n\nThere\ are\ commands\ that\ interpret\ words\ as\ numbers\ in\ order\ to\ get\ some\ math\ndone,\ but\ it's\ up\ to\ each\ individual\ command\ to\ decide\ how\ it\ wants\ to\ treat\nany\ particular\ word.\ \ Tcl\ makes\ no\ distinction.\n\n\n\n**\ Escaping\ Interpretation\ **\n\nIn\n\n======\nputs\ Hello\n======\n\n,\ there\ are\ no\ quotes\ around\ `Hello`.\ \ No\ quotes\ are\ needed\nin\ Tcl\ because\ all\ words,\ including\ the\ names\ of\ commands,\ are\ just\ strings.\nIn\ fact,\ in\ Tcl,\ \[everything\ is\ a\ string%|%every\ value\ is\ a\ string\].\ \ Because\ of\nthis,\ quotes\ are\ not\ used\ to\ signify\ that\ something\ is\ a\ string\ -\ that's\nalready\ a\ given.\ \ Instead,\ quotes,\ braces,\ and\ backslashes\ are\ used\ to\ take\naway\ the\ special\ meaning\ that\ some\ characters\ have.\ \ Whitespace\ normally\ has\ a\nspecial\ meaning\ to\ Tcl,\ since\ it\ separates\ words\ in\ a\ command.\ \ To\ include\ \nwhitespace\ characters\ as\ part\ of\ a\ value,\ use\ backslash,\ braces,\ quotes\ to\ tell\ Tcl\ not\ to\ see\ that\ whitespace\ as\ a\ word\ delimiter.\n\n`\[set\]`\ only\ takes\ two\ arguments.\ \ Therefore,\ this\ code\n\n======\nset\ foo\ good\ afternoon\n======\n\nwill\ result\ in\n\n======none\nerror:\ wrong\ #\ args:\ should\ be\ \"set\ varName\ ?newValue?\"\n======\n\nWe\ need\ to\ tell\ Tcl\ that\ the\ space\ between\ `good`\ and\ `afternoon`\ is\ part\ of\nthe\ value.\ \ Here\ is\ an\ example\ of\ doing\ that\ using\ backslash,\ braces,\ and\nquotes,\ repectively:\n\n======\nset\ foo\ good\\\ afternoon\ \nset\ foo\ \{good\ afternoon\}\nset\ foo\ \"good\ afternoon\"\n======\n\n\nBraces\ and\ quotes\ only\ have\ this\ special\ meaning\ when\ they\ completely\ enclose\ a\ word\ of\ a\ Tcl\ command.\ \ In\ the\ middle\ of\ a\ word,\ they\ are\ just\ regular\ characters.\n\n======\nputs\ This\"is\{a\"single\}\"value\n======\n\nNot\ even\ newlines\ can\ stop\ braces:\n\n======\nputs\ \{This\ is\ a\ whole\n\ \ \ paragraph\ inside\ braces.\ \ Braces\ just\n\ \ \ don't\ quit\ until\ the\ matching\ closing\ brace\n\ \ \ is\ found.\ \ Backslashed\ \\\}\ braces\ don't\ close\ it\ Off.\ \ Neither\n\ \ \ do\ \"Quotes\".\ \ \{other\ matching\ braces\}\ are\ OK,\ too.\ \ But\ finally,\n\ \ \ we\ get\ to\ the\ closing\ brace.\n\}\n======\n\n\n\n**\ Using\ Variables\ **\n\nUse\ `\[set\]`\ to\ set\ the\ value\ of\ a\ variable:\n\n\n======\nset\ greeting\ Hello\n======\n\nTo\ get\ the\ value\ back\ out\ of\ a\ variable\ use\ a\ dollar\ sign.\ \ For\ example,\ to\nprint\ `Hello`:\n\n======\nputs\ \$greeting\n======\n\nThis\ works\ even\ if\ there\ is\ white\ space\ in\ the\ greeting:\n\n======\nset\ greeting\ \{Hello\ There\}\nputs\ \$greeting\n======\n\nThat's\ because\ Tcl\ substitutes\ the\ entire\ value\ of\ the\ variable\ into\ the\ the\nspot\ where\ `\$greeting`\ was.\n\n\n\n**\ Command\ Substitution\ **\n\nVariable\ substitution\ isn't\ the\ only\ substitution\ game\ in\ town.\ \ There's\ also\ncommand\ substitution.\ \ This\ is\ done\ with\ square\ brackets.\ \ To\ print\ `Hello`\ to\nthe\ screen\ using\ command\ substitution:\n\n======\nset\ greeting\ Hello\nputs\ \[set\ greeting\]\n======\n\nWhen\ `\[set\]`\ only\ gets\ one\ argument\ instead\ of\ two,\ it\ returns\ the\nvalue\ of\ the\ variable\ instead\ of\ setting\ it.\n\nNotice\ also\ that\ we\ just\ used\ the\ name\ of\ the\ variable\ without\ prepending\ a\ndollar\ sign\ to\ it.\ \ If\ we\ had\ prepended\ the\ dollar\ sign,\ it\ would\ have\ been\nequivalent\ to\ typing\ `set\ Hello`,\ in\ which\ case\ `\[set\]`\ would\ have\ gone\ to\nfind\ the\ value\ of\ the\ variable\ named,\ \"Hello\",\ failed\ to\ find\ it,\ and\ returned\nan\ error.\n\nKnowing\ that,\ you\ should\ be\ able\ to\ make\ sense\ of\ the\ following\ code:\n\n======\nSet\ Hello\ Howdy\nset\ greeting\ Hello\nputs\ \[set\ \$greeting\]\n======\n\nWhat\ will\ be\ printed\ to\ the\ screen?\ \ That's\ right:\n\n======none\nHowdy\n======\n\n'''Extra\ Credit'''\ (not\ really\ a\ beginner\ thing):\n\n======\nputs\ \[expr\ \$\$greeting\]\n======\n\nWhat\ will\ be\ printed?\ \ Yes,\ once\ again,\ it's\n\n\n======none\nHowdy\n======\n\nWhy?\ \ Hint:\ what\ does\ `\[\[puts\ \$\$\]`\ do?\n\n----\n\n\[Clif\ Flynt\]:\ When\ I'm\ teaching\ a\ class,\ I\ point\ out\ that\n\n======\nset\ set\ set\n======\n\nis\ a\ valid\ command,\ and\ that\n\n======\nset\ x\ set\nset\ y\ a\nset\ z\ b\n\$x\ \$y\ \$z\n======\n\nis\ a\ valid\ Tcl\ command\ to\ assign\ the\ value\ b\ to\ variable\ a.\ Looking\ at\ this\nmakes\ the\ students\ stop\ and\ think.\ And\ stare\ at\ me\ like\ I'm\ crazy.\n\n\n\n**\ Commenting\ Code\ **\n\nSometimes,\ particularly\ when\ we\ think\ we're\ doing\ something\ really\ clever,\ we\nwant\ to\ add\ comments\ to\ our\ code\ so\ that\ other\ humans\ can\ make\ more\ sense\ of\nit.\ \ To\ do\ this\ in\ Tcl,\ we\ use\ the\ pound\ character,\ but\ only\ at\ the\ beginning\nof\ a\ command:\n\n\n======\n#puts\ \{This\ line\ won't\ ever\ happen,\ because\ it's\ commented\}\nputs\ Whew!\n======\n\n\n\n**\ Using\ Double\ Quotes\ **\ \n\nBraces\ inhibit\ variable\ substitution,\ command\ substitution,\ and\ most\ backslash\nsubstitution:\n\n======\nset\ name\ John\n\n#warning\ -\ This\ next\ line\ won't\ substitute\ in\ John.\ \ It\ just\ prints\ exactly\n#what\ is\ in\ the\ braces,\ including\ the\ \$.\nputs\ \{Hello\ \$name\}\n======\n\n\nWhen\ we\ want\ those\ substitutions,\ but\ we\ also\ need\ white\ space\ to\ just\ be\ white\nspace,\ we\ can\ use\ double\ quotes\ instead\ of\ braces.\ \ Double\ quotes\ have\ the\ same\npurpose\ as\ braces,\ but\ also\ allow\ all\ substitutions:\n\n======\nset\ name\ John\nset\ greeting\ \"Hello,\ \$name!\ \ Hello\ again,\ \[set\ name\]!\"\ \n======\n\n\nAs\ with\ braces,\ newlines\ inside\ quotes\ are\ just\ newlines:\n\n======\nputs\ \"In\ double\ quotes,\ newlines\n\ \ \ \ are\ \ just\ newlines.\ \ If\ you\ escape\ a\ newline,\ \\\n\ \ \ \ it\ disappears\ entirely.\ \ Braces\ are\ just\ \{braces\},\n\ \ \ \ and\ other\ \\\"double\ quotes\\\"\ can\ be\ escaped.\ \[\n\ \ \ \ \ \ \ \ set\ value\ \{Command\ Substitution,\ which\ should\ really\ be\ called\n\ \ \ \ \ \ \ \ \"script\ substitution\"\}\n\ \ \ \ \ \ \ \ set\ value\n\ \ \ \ \],\ is\ also\ not\ a\ problem\ at\ all.\ \ Notice\ that\ there\ were\ multiple\ commands\n\ \ \ \ in\ that\ last\ command\ substitution,\ and\ the\ value\ of\ the\ last\ command\ is\ what\n\ \ \ \ actually\ takes\ the\ place\ of\ the\ entire\ command\ substitusion.\ \ It\ doesn't\n\ \ \ \ hurt\ to\ escape\ \\\{braces\\\},\ but\ it\ isn't\ necessary,\ either.\ \ Escaping\ regular\ \\letters\n\ \ \ \ doen't\ do\ anything\ at\ all\ to\ them.\ \ An\ \\a\ is\ just\ an\ a.\ \ Finally,\ we\ get\n\ \ \ \ to\ the\ closing\ quote.\"\n\"\n======\n\n\n\n**\ Using\ Backslashes\ **\n\n\nIn\ addition\ to\ variable\ and\ command\ substitution,\ there\ is\ on\ other\ substituion\ndevice:\ \ Backslashes.\ \ They\ are\ used\ in\ Tcl\ in\ a\ manner\ very\ similar\ to\ that\ of\n\[C\]/\[C++\].\ The\ following\ are\ backslash\ substitutions\ understood\ by\ Tcl:\n\n\ \ \ '''`\\a`''':\ \ \ Audible\ alert\ (bell)\ (0x7)\n\ \ \ '''`\\b`''':\ \ \ Backspace\ (0x8)\n\ \ \ '''`\\f`''':\ \ \ Form\ feed\ (0xc)\ \n\ \ \ '''`\\n`''':\ \ \ Newline,\ LF\ (0xa)\n\ \ \ '''`\\r`''':\ \ \ Carriage-return,\ CR\ (0xd)\n\ \ \ '''`\\t`''':\ \ \ Tab\ (0x9)\n\ \ \ '''`\\v`''':\ \ \ Vertical\ tab\ (0xb)\n\nThe\ additional\ backslash\ sequences,\ '''`\\x`'''\ and\ '''`\\u`''',\ are\ some\ndocumented\ in\ the\ \[Dodekalogue\].\ \ They\ point\ to\ the\ fact\ that\ Tcl\ is\ not\nrestricted\ to\ 8-bit\ characters,\ a\ limitation\ of\ some\ other\ languages.\n\nIf\ a\ `\\`\ is\ followed\ by\ up\ to\ 3\ digits\ of\ numbers,\ than\ it\ is\ treated\ as\ an\noctal\ value\ for\ a\ character\ and\ the\ actual\ character\ is\ then\ substituted\ in\ its\nplace.\n\nAny\ other\ character\ following\ a\ `\\`\ is\ replace\ with\ itself.\ This\ is\ an\ 'escape'\nmechanism\ that\ enables\ you\ to\ make\ character\ just\ be\ themselves\ in\ places\ where\nTcl\ would\ normally\ assign\ some\ special\ meaning\ to\ them:\n\n======\nputs\ \"what\ do\ we\ mean\ when\ we\ say,\ \\\"word\\\"?\"\n======\n\nIf\ a\ backslash\ '''\\'''\ appears\ at\ the\ end\ of\ a\ line,\ then\ that\ line\ continues\non\ to\ the\ next\ line:\n\n======\nputs\ \\\n\ \ \"Continued\ from\ the\ line\ above\"\n======\n\nThis\ is\ to\ allow\ a\ long\ line\ of\ code\ to\ be\ split\ into\ multiple\ lines\ if\ you\ run\nout\ of\ space\ in\ your\ text\ editor.\n\n\n\n**\ Word\ Expansion\ **\n\nSometimes\ we\ need\ a\ way\ to\ tell\ Tcl\ to\ consider\ each\ word\ within\ a\ word\ to\ be\nan\ additional\ argument\ to\ a\ command.\ \ For\ example,\ if\ we\ have\ a\ variable\ that\ncontains\ two\ words:\n\n======\nset\ attribute\ \{name\ Bob\}\n======\n\nThe\ following\ would\ result\ in\ a\ four-word\ command,\ including\ the\ name\ of\ the\ncommand:\n\n======\nformat\ \{%s:\ %s\}\ \{*\}\$attribute\n======\n\nThis\ is\ called\ \"word\ expansion\".\n\n\n**\ It's\ really\ All\ about\ Commands\ **\n\nThe\ few\ rules\ that\ have\ just\ been\ described\ constitute\ the\ entirety\ of\ the\ Tcl\nlanguage.\ \ Really!\ \ That's\ it.\ \ There's\ nothing\ more.\ \ The\ description\ above\ is\na\ complete\ description\ of\ the\ Tcl\ language.\ \ There\ doesn't\ need\ to\ be\ anything\nmore\ because\ those\ rules\ are\ entirely\ sufficient\ to\ create\ every\ other\nprogramming\ facility\ that\ exists\ in\ Tcl.\n\nThe\ only\ thing\ you\ will\ ever\ do\ in\ Tcl\ code\ is\ form\ commands.\ \ There\ are\ no\n\[control\ structure%|%control\ structures\]\ in\ \ the\ syntax\ because\ control\ flow\ can\nbe,\ and\ is,\ implemented\ as\ commands.\ \ That's\ why\ Tcl\ really\ is\ all\ about\ the\ncommands.\ \ There\ are\ two\ types\ of\ commands\ which\ may\ be\ considered\ fundamental:\ncommands\ that\ create\ new\ commands,\ i.e.,\ `\[proc\]`,\ and\ commands\ that\nimplement\ conditional\ constructs,\ i.e.,\ `\[if\]`.\n\n\n\n**\ Creating\ New\ Commmands\ **\n\n`\[proc\]`\ is\ used\ to\ create\ new\ commands.\n\n======\nproc\ greet\ \{\}\ \{\n\ \ \ \ puts\ Hello!\n\}\n======Commands\ that\ have\ been\ created\ this\ way\ are\ called\ procedures.\n\nTo\ create\ a\ procedure\ that\ takes\ an\ argument:\n\n======\nproc\ greet\ name\ \{\n\ \ \ \ puts\ \"greeting,\ \$name!\"\n\}\n======\n\nTo\ create\ a\ procedure\ that\ takes\ multiple\ arguments:\n\n======\nproc\ greet\ \{first\ last\}\ \{\n\ \ \ \ puts\ \"hello,\ \$first\ \$last!\"\n\}\n======\n\nSince\ `\[proc\]`\ interprets\ its\ second\ argument\ as\ a\ list,\ the\ following\ works\ as\ well,\ but\ is\ not\ common:\n\n======\nproc\ greet\ \[list\ first\ last\]\ \{\n\ \ \ \ puts\ \"hello,\ \$first\ \$last!\"\n\}\n======\n\nThe\ last\ command\ within\ a\ procedure\ is\ returned\ as\ the\ value\ of\ a\ procedure.\n\n\n======\nproc\ combine\ \{part1\ part2\}\ \{\n\ \ \ \ set\ result\ \$part1\$part2\n\}\ncombine\ hel\ lo\n======\n\nThe\ result\ is:\n\n======none\nhello\n======\n\n`\[return\]`\ can\ be\ used\ to\ be\ more\ explicit.\ \ The\ following\ example\ has\ the\nsame\ result\ as\ the\ previous\ one.\n\n======\nproc\ combine\ \{part1\ part2\}\ \{\n\ \ \ \ return\ \$part1\$part2\n\}\ncombine\ hel\ lo\n======\n\nThere's\ a\ special\ trick\ to\ creating\ a\ procedure\ that\ takes\ a\ variable\ number\ of\narguments.\ \ If\ the\ last\ name\ in\ the\ list\ of\ arguments\ is\ `args`,\nthe\ new\ procedure\ can\ be\ called\ with\ any\ number\ of\ args,\ and\ within\ the\nprocedure,\ \$args\ will\ be\ a\ list\ of\ the\ extra\ arguments:\n\n======\nproc\ greet\ \{greeting\ args\}\ \{\n\ \ \ \ foreach\ name\ \$args\ \{\n\ \ \ \ \ \ \ \ puts\ \"\$greeting,\ \$name!\"\n\ \ \ \ \}\n\}\n======\n\nTo\ create\ a\ procedure\ that\ can\ be\ invoked\ with\ any\ number\ of\ arguments,\ or\ none\ at\ all:\n\n======\nproc\ count\ args\ \{\n\ \ \ \ set\ length\ \[llength\ \$args\]\n\ \ \ \ if\ \{\$length\ ==\ 0\}\ \{\n\ \ \ \ \ \ \ \ puts\ \"I\ was\ invoked\ with\ no\ arguments\"\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ puts\ \"I\ was\ invoked\ with\ \$length\ arguments\"\n\ \ \ \ \}\n\}\n======\n\nAnd\ it\ works\ like\ that:\n\n======\n%\ count\nI\ was\ invoked\ with\ no\ arguments\n%\ count\ a\nI\ was\ invoked\ with\ 1\ arguments\n%\ count\ a\ b\nI\ was\ invoked\ with\ 2\ arguments\n======\n\n\n**\ Conditional\ Constructs\ **\n\n\n`\[if\]`,\ a\ necessary\ construct\ in\ any\ language,\ in\ Tcl\ is\ just\ another\ncommand.\ \ It\ takes\ a\ word\ that\ serves\ as\ the\ condition,\ and\ another\ word\ that\nserves\ as\ the\ script\ to\ run\ in\ the\ event\ that\ the\ criteria\ is\ true:\n\n\n======\nif\ \{1\}\ \{\n\ \ \ \ puts\ \"1\ is\ always\ true!\"\n\}\n======\n\nNotice\ that\ `1`\ is\ braced,\ even\ though\ it\ wasn't\ strictly\ necessary.\ \ Why?\ \ To\nadvocate\ \[Brace\ your\ expr-essions%|%good\ programming\ habits\].\ \ Until\ you\ learn\nenought\ to\ know\ exactly\ when\ not\ to,\ you\ should\ '''always'''\ \[Brace\ your\nexpr-essions%|%brace\ your\ expressions\].\n\n\nHere's\ another\ example:\n\n======\nif\ \{0\}\ \ \{\n\ \ \ \ Anything\ at\ all\ can\ go\ here,\n\ \ \ \ even\ syntactically-invalid\\\{\n\ \ \ \ stuff,\ because\ Tcl\ will\ not\ attempt\n\ \ \ \ to\ evaluate\ this\ word,\ as\ the\ condition\ is\ false.\n\}\n======\n\n\n\n**\ What\ is\ a\ \[list\]?\ **\n\nThe\ Tcl\ \[Dodekalogue%|%language\ specification\]\ doesn't\ have\ anything\ to\ say\nabout\ \[list%|%lists\],\ except\ that\ some\ command\ might\ interpret\ words\ passed\ to\ them\ as\nvarious\ things,\ including\ possibly\ lists.\ \ It\ does\ specify,\ however,\ that\ a\nscript\ is\ a\ string,\ and\ can\ be\ broken\ down\ into\ commands,\ which\ therefore\ must\ also\nbe\ strings.\ \ Commands,\ in\ turn,\ are\ composed\ of\ words.\ \ This\ strongly\ implies\nthat\ the\ syntax\ of\ a\ command\ must\ be\ adequate\ to\ express\ a\ list.\ \ The\ \nbuilt-in\ `\[list\]`\ commands\ of\ Tcl\ accept\ a\ word\ as\ a\ list\ if\ and\ only\nif\ the\ word\ in\ turn\ can\ be\ parsed\ as\ a\ Tcl\ command.\ \ In\nother\ words,\ a\ list\ is\ a\ string\ that\ could\ be\ interpreted\ as\ a\ command.\n\n======\nset\ a\ \"A\ B\ C\"\nlindex\ \$a\ 0\n======\n\nThe\ above\ commands\ return\ :\n\n======none\nA\ B\ C\nA\n======\n\nHowever,\ not\ every\ string\ that\ can\ be\ interpreted\ as\ a\ command\ is\ a\ list.\n\n======\nset\ command\ \{list\ \{*\}\{one\ two\ three\}\}\nlindex\ \$command\ 0\ \;#\ ->\ error:\ list\ element\ in\ braces\ followed\ by\ \"\{one\"\ instead\ of\ space\n======\n\nThe\ meaning\ of\ `\{*\}`\ is\ discussed\ later.\n\n\n`\[lindex\]`\ returns\ the\ list\ element,\ located\ at\ the\ given\ index.\ Indices\nstart\ at\ `0`.\n\n======\nset\ a\ \{A\ B\ C\}\nlindex\ \$a\ 1\n======\n\nresult:\n\n======\nB\n======\n\nIt's\ possible\ for\ a\ list\ to\ contain\ another\ list:\n\n\n======\nset\ a\ \"A\ \{B\ C\}\ D\"\nlindex\ \$a\ 1\n======\n\nresult:\n\n======none\nA\ \{B\ C\}\ D\nB\ C\n======\n\nRemember\ that\ not\ all\ strings\ are\ lists.\n\nAlthough\ `\[split\]`\ can\ be\ used\ to\ convert\ any\ string\ into\ a\ list\ of\ words,\nthat\ doesn't\ mean\ that\ any\ value\ given\ to\ `\[split\]`\ is\ a\ well-formed\nlist.\n\n\n\n**\ DO\ **\n\n\ \ \ *\ Do\ write\ lots\ of\ comments\ in\ your\ code\ about\ what\ your\ code\ does,\ what\ you\ tried\ that\ didn't\ work\ (and\ why,\ if\ known).\n\ \ \ *\ Do\ study\ the\ documentation\ and\ others'\ code\ to\ understand\ 'upvar',\ 'uplevel'.\n\n\ \ \ *\ Learn\ how\ to\ use\ `\[exec\]`\ so\ that\ you\ can\ start\ using\ Tcl\ to\ drive\ external\ programs\n\n\n**\ DON'T\ **\n\n\ \ \ *\ Don't\ have\ unescaped\ unmatched\ brackets\ ANYWHERE,\ including\ comments.\ \ Use\ a\ text\ editor\ that\ helps\ you\ by\ showing\ bracket\ matching.\ \ \n\n\n**\ Getting\ Stuff\ Done\ \ **\n\n\ \ \ *\ \[tcllib\]\ is\ full\ of\ useful\ code.\ Try\ to\ use\ it\ as\ much\ as\ possible,\ a\ wide\ use\ of\ \[tcllib\]\ really\ saves\ time,\ and\ it\ is\ frequently\ updated.\n\n\ \ \ *\ If\ you\ need\ speed,\ be\ aware\ that\ Tcl\ can\ be\ extended\ easily\ (using\ \[C\],\[C++\]...).\ Avoid\ writing\ your\ own\ extensions\ if\ existing\ ones\ can\ do\ the\ job.\n\n\ \ \ *\ Do\ split\ your\ code\ into\ different\ \[namespace\]s\ (and\ files)\ when\ it\ overcomes\ ca.\ a\ thousand\ lines.\n\n\n\n<<categories>>\ Tutorial} CALL {my revision {TCL for beginners}} CALL {::oo::Obj110658 process revision/TCL+for+beginners} CALL {::oo::Obj110656 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4