Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/TCL+for+beginners?V=29
QUERY_STRINGV=29
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.178.205
REMOTE_PORT12196
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.133.85.191
HTTP_CF_RAY886945feba666354-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.133.85.191
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} written\ by\ \[slebetman\]\n\n'''The\ Zen\ of\ the\ Tcl'''\n\nTcl\ is\ probably\ not\ like\ any\ other\ programming\ language\ you\ are\ likely\ to\ encounter.\ The\ best\ way\ to\ approach\ Tcl\ is\ to\ think\ of\ the\ command\ line,\ be\ it\ DOS\ or\ bash\ or\ tcsh\ or\ Cisco's\ telnet\ shell.\n\nAll\ statements\ in\ Tcl\ work\ just\ like\ running\ a\ program\ from\ the\ command\ line.\ That\ is,\ the\ first\ word\ is\ a\ ''command''\ and\ the\ following\ words\ are\ ''parameters''\ to\ that\ command.\ For\ example,\ in\ DOS\ to\ list\ the\ contents\ of\ a\ directory\ you\ would\ type:\n\n\ \ dir\ c:\\path\\to\\folder\n\nin\ Tcl\ you\ would\ write:\n\n\ \ glob\ /path/to/folder/*\n\nJust\ like\ in\ DOS,\ the\ first\ word\ of\ a\ Tcl\ statement\ is\ always\ a\ command.\ Simple\ isn't\ it?\n\nThe\ ''glob''\ command\ is\ just\ one\ of\ the\ commands\ available\ in\ Tcl.\ Another\ useful\ command\ is\ the\ ''puts''\ command.\ It\ simply\ prints\ things\ out\ on\ the\ screen.\ Try\ it:\n\n\ \ puts\ \"Hello\ World!\"\n\nYou\ may\ think\ of\ it\ as\ '''put'''\ '''s'''tring\ but\ I\ usually\ think\ of\ it\ as\ the\ plural\ of\ put\ (since\ it\ can\ output\ more\ than\ one\ character).\n\nNotice\ that\ ''puts''\ is\ similar\ to\ the\ ''echo''\ command\ in\ DOS\ and\ Unix\ shells.\ Again,\ this\ shows\ how\ simple\ Tcl\ is.\n\n'''Any\ Comments?..'''\n\nIn\ Tcl\ any\ command\ (first\ word\ in\ a\ statement)\ that\ begins\ with\ the\ '''#'''\ character\ is\ ignored.\ This\ is\ how\ one\ inserts\ comments.\ Comments\ are\ nice\ since\ they\ allow\ you\ do\ document\ things\ which\ may\ not\ be\ obvious\ in\ your\ code.\n\n\ \ \ #This\ is\ a\ comment\n\ \ \ #\ the\ Tcl\ interpreter\ will\ ignore\ comments\ so\ you\ can\ say\ whatever\ you\ like\ \;-)\n\n'''Variables\ and\ Values'''\n\nIn\ all\ programming\ languages,\ you\ use\ variables\ to\ store\ values.\ Some\ languages\ prevent\ you\ from\ storing\ different\ kinds\ of\ values\ into\ different\ kinds\ of\ variables.\ But\ we'll\ have\ none\ of\ that\ here.\ In\ Tcl\ a\ variable\ can\ hold\ anything\ (even\ complete\ programs\ if\ you\ want\ to).\ Variables\ will\ even\ hold\ your\ hand:\n\n\ \ set\ my_variable\ \"your\ hand\"\n\nwell..\ maybe\ not\ '''your'''\ hand,\ but\ the\ code\ above\ stores\ the\ string\ \"your\ hand\"\ into\ a\ variable\ called\ my_variable.\ The\ ''set''\ command\ is\ used\ to\ assign\ values\ to\ variables.\ It\ can\ also\ be\ used\ to\ get\ the\ value\ contained\ by\ the\ variable:\n\n\ \ #assign\ value:\n\ \ set\ new_var\ 100\n\n\ \ #get\ value\ and\ print\ it\ on\ screen\n\ \ puts\ \[set\ new_var\]\n\nProgrammers\ usually\ don't\ like\ typing\ too\ much.\ So\ Tcl\ provides\ a\ kind\ of\ shortcut\ to\ get\ the\ value\ of\ variables\ without\ using\ the\ ''set''\ command.\ Simply\ add\ a\ '''\$'''\ sign\ in\ front\ of\ the\ variable\ to\ get\ its\ value:\n\n\ \ #another\ way\ to\ get\ value\ of\ variables\n\ \ puts\ \$new_var\n\n\ \ #you\ can\ even\ assign\ values\ of\ other\ variables\ to\ a\ varaible:\n\ \ set\ my_variable\ \$new_var\n\nNotice\ that\ when\ one\ uses\ the\ ''set''\ command\ on\ a\ variable,\ one\ uses\ the\ variable\ without\ the\ '''\$'''\ sign.\ This\ is\ because\ the\ '''\$'''\ sign\ is\ not\ used\ to\ signify\ a\ variable\ like\ in\ Perl\ but\ is\ merely\ a\ shortcut\ for\ getting\ its\ value.\n\nJust\ for\ fun,\ what\ do\ you\ think\ happens\ in\ the\ following\ code?\n\n\ \ set\ foo\ \"this\ is\ cool\"\n\ \ set\ bar\ foo\n\ \ puts\ \[set\ \$bar\]\n\nIn\ the\ first\ statement,\ the\ variable\ ''foo''\ is\ set\ to\ hold\ the\ string\ ''\"this\ is\ cool\"''.\ The\ variable\ ''bar''\ is\ then\ set\ to\ the\ word\ ''\"foo\"''.\ Notice\ that\ there\ is\ no\ '''\$'''\ sign\ in\ front\ of\ ''foo''.\ This\ means\ that\ ''bar''\ is\ not\ assigned\ the\ '''value'''\ of\ ''foo''\ but\ just\ simply\ the\ word\ ''foo''.\n\nThe\ interesting\ part\ is\ the\ third\ statement.\ The\ ''set''\ command\ is\ used\ to\ get\ the\ value\ of\ ''\$bar''.\ Since\ ''bar''\ itself\ contains\ the\ word\ ''foo'',\ what\ happens\ is\ we\ get\ the\ value\ contained\ in\ the\ value\ of\ ''bar''.\ Confused?\n\nLet's\ examine\ the\ third\ line\ step\ by\ step.\ The\ '''\$'''\ sign\ is\ a\ shortcut\ to\ get\ the\ value\ of\ a\ variable.\ So\ ''\$bar''\ returns\ the\ word\ ''foo''.\ The\ ''set''\ command\ then\ gets\ the\ value\ of\ ''foo''\ and\ returns\ the\ string\ ''\"this\ is\ cool\"''.\ The\ third\ line\ can\ also\ be\ written\ as:\n\n\ \ puts\ \[set\ \[set\ bar\]\]\n\nbut\ writing\ ''\$\$bar''\ does\ not\ work.\ This\ is\ because\ '''\$\$'''\ is\ not\ something\ Tcl\ understands.\n\n'''Groupings'''\n\nThere\ are\ several\ things\ I\ did\ not\ explain\ in\ the\ examples\ above.\ One\ of\ which\ is\ the\ use\ of\ the\ double\ quotes\ (\").\ I\ know\ what\ you're\ thinking:\ I\ know\ that,\ it's\ a\ string.\ Correct...,\ but\ not\ quite.\ You\ see,\ in\ Tcl,\ everything\ is\ a\ string\ until\ it\ needs\ to\ be\ something\ else.\ Even\ 200\ is\ a\ string\ until\ you\ try\ to\ add\ 1\ to\ it.\ What\ the\ quotes\ represent\ in\ Tcl\ is\ grouping\ -\ a\ far\ simpler\ and\ powerful\ concept.\n\nLet's\ take\ a\ look\ at\ the\ ''set''\ command.\ It\ accepts\ either\ one\ or\ two\ parameters.\ If\ there\ are\ two\ parameters\ then\ the\ second\ parameter\ is\ a\ value\ to\ be\ assigned\ to\ the\ first\ parameter\ (which\ is\ a\ variable\ name).\ What\ if\ our\ string\ consists\ of\ more\ than\ one\ word?\ Trying\ to\ do:\n\ \ set\ foo\ this\ is\ cool\nwill\ result\ in\n\ \ error:\ wrong\ #\ args:\ should\ be\ \"set\ varName\ ?newValue?\"\nwhy?\ because\ we\ are\ given\ '''set'''\ four\ parameters,\ instead\ of\ two.\ we\ should\ write:\ \n\ \ set\ foo\ \"this\ is\ cool\"\n\n\nSo\ Tcl\ provides\ mechanisms\ to\ group\ words\ together.\ In\ the\ earlier\ example,\ foo\ is\ the\ first\ parameter\ and\ \"this\ is\ cool\"\ is\ the\ second,\ grouped\ by\ the\ quotes.\n\nTcl\ provides\ two\ ways\ to\ group\ things:\ the\ double\ quotes\ \"\ and\ curly\ braces\ \{\}.\ The\ above\ example\ would\ also\ work\ with:\n\n\ \ set\ foo\ \{this\ is\ cool\}\n\nWhat's\ the\ difference?\ Why\ two\ kinds\ of\ groupings?\ Well,\ things\ grouped\ with\ the\ double\ quotes\ will\ go\ through\ ''substitution''.\ Things\ grouped\ with\ braces\ will\ be\ left\ alone.\ You're\ saying\ what??..\ Lets\ see\ an\ example:\n\n\ \ set\ foo\ 100\n\ \ puts\ \{example1\ \$foo\}\n\ \ puts\ \"example2\ \$foo\"\n\nThe\ above\ code\ will\ print\ out:\n\n\ \ example1\ \$foo\n\ \ example2\ 100\n\nthat's\ because\ the\ first\ ''puts''\ statement\ is\ left\ alone\ while\ the\ second\ one\ is\ substituted.\n\n'''Substitution'''\n\nWe\ have\ seen\ one\ kind\ of\ substitution\ already.\ That\ is\ the\ '''\$'''\ shortcut.\ This\ is\ called\ ''variable\ substitution''\ because\ it\ replaces\ the\ variable\ with\ its\ value.\ Substitutions\ are\ what\ makes\ Tcl\ tick.\ It\ is\ a\ powerful,\ flexible\ and\ simple\ concept.\ There\ are\ three\ kinds\ of\ substitutions\ in\ Tcl:\ variable\ substitutions,\ command\ substitutions\ and\ backslash\ substitutions.\n\nWe\ have\ already\ seen\ variable\ substitution\ and\ it\ is\ explained\ above.\ It\ simply\ substitutes\ the\ value\ of\ the\ variable\ in\ place\ of\ the\ variable\ itself\ when\ a\ '''\$'''\ sign\ is\ added\ in\ front\ of\ the\ variable.\n\nCommand\ substitution\ is\ similar\ in\ that\ it\ substitutes\ the\ result\ of\ a\ command\ in\ place\ of\ the\ command.\ We\ have\ in\ fact\ already\ seen\ this\ above,\ but\ I\ did\ not\ explain\ it.\ Basically\ a\ statement\ between\ square\ brackets\ '''\[\[\ \]\]'''\ is\ treated\ as\ a\ command\ and\ is\ evaluated.\ The\ result\ is\ then\ substituted\ in\ its\ place.\ For\ example:\n\n\ \ set\ bat\ \"a\ list\ of\ files\ in\ the\ current\ directory:\ \[glob\ *\]\"\n\nThe\ glob\ command\ is\ evaluated,\ and\ its\ result\ is\ inserted\ into\ the\ string\ which\ is\ then\ assigned\ to\ the\ variable\ ''bat''.\ We\ have\ seen\ similar\ syntax\ in\ the\ various\ ''set''\ and\ ''puts''\ examples\ above.\n\nBackslash\ substitution\ is\ very\ similar\ to\ 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\nAlso,\ if\ a\ '''\\'''\ is\ followed\ by\ up\ to\ 3\ digits\ of\ numbers,\ than\ it\ is\ treated\ as\ an\ octal\ value\ for\ a\ character\ and\ the\ actual\ character\ is\ then\ substituted\ in\ its\ place.\n\nAny\ other\ character\ following\ a\ '''\\'''\ is\ replace\ with\ itself.\ This\ is\ an\ 'escape'\ mechanism\ that\ enables\ you\ to\ include\ special\ characters:\n\n\ \ puts\ \"This\ is\ how\ you\ print\ the\ double\ quote\ (\\\")\"\n\nIn\ addition,\ if\ a\ backslash\ '''\\'''\ appears\ at\ the\ end\ of\ a\ line,\ then\ that\ line\ continues\ on\ to\ the\ next\ line:\n\n\ \ puts\ \\\n\ \ \ \ \"Continued\ from\ the\ line\ above\"\n\nThis\ is\ to\ allow\ a\ long\ line\ of\ code\ to\ be\ split\ into\ multiple\ lines\ if\ you\ run\ out\ of\ space\ in\ your\ text\ editor.\n----\n\nSee\ also:\ http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm\n----\n'''What\ is\ a\ list?'''\n\nIn\ Tcl,\ everything\ is\ a\ string.\ But\ what\ is\ a\ list?\ It\ is\ basically,\ a\ string\ in\ which\ elements\ are\ separated\ by\ spaces.\nabout\ \[list%|%lists\],\ except\ that\ some\ command\ might\ interpret\ words\ passed\ to\ them\ as\n\ set\ a\ \"A\ B\ C\"\n\ lindex\ \$a\ 0\nset\ a\ \"A\ B\ C\"\n======none\n\ A\ B\ C\n\ A\nA\ B\ C\n\[lindex\]\ returns\ a\ list\ element,\ located\ at\ a\ given\ index.\ Indices\ start\ at\ 0.\nset\ command\ \{list\ \{*\}\{one\ two\ three\}\}\n\ set\ a\ \{A\ B\ C\}\n\ lindex\ \$a\ 1\n\nreturns\ \"B\".\nB\n--\ \[Sarnold\]\ 2005/11/27\n\n----\n\n\[JM\]\ slebetman:\ I\ would\ like\ to\ participate\ in\ this\ page,\ I\ can\ suggest\ an\ idea\ that\ I\ think\ fits,\ then\ if\ you\ agree\ I\ can\ insert\ the\ text\ where\ I\ think\ it\ belongs,\ so\ I\ don't\ mess\ original\ idea\ of\ this\ page.\n\nexample:\nfor\ the\ \"any\ comments?\"\ section,\ we\ can\ include\ that,\ a\ common,\ alternative\ way\ to\ insert\ comments\ in\ tcl\ (and\ I\ think\ not\ just\ in\ tcl)\ is\ by\ means\ of:\n\ if\ \{0\}\ \ \{these\ are\ the\ comments\}\nwhich\ is\ really\ code\ that\ is\ never\ executed.\n\n\[slebetman\]\ I'd\ wait\ until\ we\ introduce\ the\ 'if'\ command.\ I\ know\ '''if'''\ is\ obvious\ to\ anyone\ who\ is\ used\ to\ programming\ in\ any\ language.\ But\ I\ want\ to\ impress\ the\ ''essence\ of\ Tcl''\ to\ newbies.\ Mixing\ syntax\ and\ command\ is\ not\ good\ in\ my\ view.\n\nBut\ thanks\ for\ your\ support.\ Please\ edit\ away\ any\ mistakes\ that\ you\ find\ here.\ But\ please\ refrain\ from\ commenting\ ''in-line''.\ Comment\ at\ the\ bottom.\ In-line\ comments\ in\ the\ text\ itself\ is\ to\ be\ considered\ transient\ and\ may\ be\ edited\ away\ once\ corrections\ are\ made.\n\nAlso,\ if\ you\ find\ ways\ to\ re-phrase\ sentences\ and\ paragraphs\ in\ a\ more\ 'friendly'\ manner,\ please\ do\ so\ (in-line\ comments\ may\ be\ appropriate\ in\ this\ case\ if\ there\ is\ no\ consensus\ yet).\ I\ want\ to\ keep\ the\ tone\ of\ this\ introduction\ fun,\ friendly\ and\ informal,\ sort\ of\ like\ for-dummies,\ maybe\ even\ more\ fun.\ Humor\ is\ very\ much\ encouraged\ but\ not\ at\ the\ expense\ clarity:\ fun,\ not\ flippant.\n\nAnyway,\ I\ think\ the\ syntax\ rules\ are\ covered.\ Feel\ free\ to\ start\ describing\ commands\ like\ '''if''',\ '''proc'''\ etc.\ Don't\ worry\ about\ which\ comes\ before/after\ which.\ We\ can\ always\ edit\ and\ re-arrange\ chapters\ later.\n\n\[Lars\ H\],\ 28\ november\ 2005:\ Well,\ there's\ no\ mention\ of\ \\x\ and\ \\u\ substitution.\ I\ find\ \\u\ interesting\ to\ mention,\ since\ it\ points\ to\ the\ fact\ that\ Tcl\ is\ not\ restricted\ to\ 8-bit\ characters,\ which\ however\ many\ other\ languages\ are.\n\n\[slebetman\]\ Good\ catch.\ Missed\ that.\ I'll\ be\ adding\ it\ later\ when\ I\ have\ time.\ Or\ you\ are\ free\ to\ do\ it\ yourself.\n\n''\[escargo\]\ 28\ Nov\ 2005''\ -\ I\ don't\ like\ spoiling\ the\ fun,\ but\ I\ think\ it's\ worthwhile\ mentioning\ some\ of\nthe\ \"gotchas\"\ of\ Tcl.\ \ For\ example,\ that\ comments\ require\ balanced\ delimiters,\ that\ commands\ that\ take\n''similar''\ parameters\ don't\ necessarily\ take\ ''identical''\ parameters\ (that\ is,\ some\ things\ can\ be\ more\nirregular\ than\ other\ languages\ because\ there\ isn't\ an\ overarching\ grammar\ that\ enforces\ regularity).\n\n''\[AET\]\ 29nov05''\ I\ agree,\ but\ there\ are\ many\ places\ where\ such\ information\ interrupts\ the\ learning\ flow.\ \ A\ simple\ '''DO'''\ and\ '''DONT'''\ list\ is\ less\ confusing\ for\ a\ beginner.\ \ And\ please,\ PLEASE\ resist\ the\ temptation\ (that\ so\ many\ have\ fallen\ to)\ to\ describe\ a\ new\ subject\ in\ terms\ of\ ''Here's\ some\ code\ that\ doesn't\ work,\ and\ here's\ why\ \ .\ .\ ''.\ \ A\ beginner\ needs\ to\ see\ and\ absorb\ simple,\ clear\ and\ above\ all\ CORRECT\ code.\ \ Please\ also\ keep\ debate\ of\ finer\ points\ of\ style,\ completeness,\ unusual\ exceptions\ etc.\ to\ other\ pages.\n\n\[slebetman\]\ I\ agree\ with\ \[AET\].\ I\ intend\ to\ give\ new\ users\ the\ 'feel'\ of\ Tcl\ which\ I\ and\ a\ lot\ of\ others\ found\ lacking\ in\ \[TCL\ programs\ for\ beginners\ 1-10\].\ This\ is\ meant\ as\ an\ introduction,\ not\ a\ complete\ description.\ By\ the\ way,\ I\ always\ wondered\ why\ the\ matching\ bracket\ thing\ is\ not\ documented\ in\ the\ 11\ rules\ of\ Tcl:\ http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm\n\nAlso,\ with\ regards\ to\ wiki\ rules\ about\ editing\ other's\ post.\ If\ the\ changes\ in\ the\ comments\ are\ implemented,\ can\ I\ delete\ the\ comment?\ Also,\ I\ hope\ others\ won't\ mind\ if\ I\ later\ re-arrange\ parts\ of\ this\ page\ to\ make\ it\ more\ coherent\ overall.\n\n\[Lars\ H\]:\ The\ \"no\ unmatched\ braces\ in\ comments\"\ restriction\ is\ only\ relevant\ in\ bodies\ (of\ \[proc\],\ \[foreach\],\ \[while\],\ etc.),\ so\ it\ is\ natural\ to\ bring\ up\ in\ that\ context,\ but\ this\ is\ too\ early\ --\ there\ hasn't\ yet\ been\ any\ example\ where\ a\ comment\ with\ an\ unmatched\ brace\ would\ spoil\ anything!\n----\n'''DO'''\n\n\ \ \ *\ Learn\ how\ to\ use\ `\[exec\]`\ so\ that\ you\ can\ start\ using\ Tcl\ to\ drive\ external\ programs\n----\n'''DON'T'''\n\ \ \ *\ Don't\ have\ unmatched\ brackets\ ANYWHERE,\ including\ comments.\ \ Use\ a\ text\ editor\ that\ helps\ you\ by\ showing\ bracket\ matching.\ \ \n\ \ \ *\ Don't\ expect\ to\ use\ an\ array\ in\ a\ proc\ till\ you\ understand\ 'upvar'.\ \ \n\ \ \ *\ Don't\ expect\ to\ drive\ external\ programs\ easily\ till\ you\ get\ the\ hang\ of\ 'exec'.\ \ \n----\n'''ESPECIALLY\ USEFUL\ TCL\ FEATURES'''\n\ \ \ *\ \[foreach\]\ is\ wonderful.\ \ Simple\ and\ powerful.\ \ \n----\n'''Code\ reusing\ and\ packaging'''\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\ \ \ *\ Do\ split\ your\ code\ into\ different\ \[namespace\]s\ (and\ files)\ when\ it\ overcomes\ ca.\ a\ thousand\ lines.\n\n----\n'''Regarding\ Variables\ and\ Values\ example'''\n\ \ set\ foo\ \"this\ is\ cool\"\n\ \ set\ bar\ foo\n\ \ puts\ \[set\ \$bar\]\n\ \ puts\ \[set\ \[set\ bar\]\]\nyet\ another\ line\ to\ add\ to\ example\ code:\n\ \ puts\ \[expr\ \$\$bar\]\n\n\[Lars\ H\]:\ I\ don't\ think\ that\ would\ be\ a\ good\ idea,\ because\ \[\[expr\ \$\$bar\]\]\n\[Lars\ H\]:\ I\ don't\ think\ that\ would\ be\ a\ good\ idea,\ because\ \[\[expr\ \$\$bar\]\]\ combines\ two\ bad\ habits\ for\ a\ Tcl\ programmer:\ not\ bracing\ \[expr\]essions\ and\ \$\ signs\ that\ fail\ to\ substitute.\ It\ can\ at\ best\ be\ a\ specimen\ for\ illuminating\ some\ of\ the\ odd\ quirks\ of\ the\ language,\ but\ it\ is\ definitely\ not\ something\ beginners\ should\ be\ exposed\ to.\n----\n\nSee\ also,\ \"\[The\ first\ article\ to\ read\ about\ Tcl\]\".\n----\n\[Category\ Tutorial\] regexp2} CALL {my render {TCL for beginners} written\ by\ \[slebetman\]\n\n'''The\ Zen\ of\ the\ Tcl'''\n\nTcl\ is\ probably\ not\ like\ any\ other\ programming\ language\ you\ are\ likely\ to\ encounter.\ The\ best\ way\ to\ approach\ Tcl\ is\ to\ think\ of\ the\ command\ line,\ be\ it\ DOS\ or\ bash\ or\ tcsh\ or\ Cisco's\ telnet\ shell.\n\nAll\ statements\ in\ Tcl\ work\ just\ like\ running\ a\ program\ from\ the\ command\ line.\ That\ is,\ the\ first\ word\ is\ a\ ''command''\ and\ the\ following\ words\ are\ ''parameters''\ to\ that\ command.\ For\ example,\ in\ DOS\ to\ list\ the\ contents\ of\ a\ directory\ you\ would\ type:\n\n\ \ dir\ c:\\path\\to\\folder\n\nin\ Tcl\ you\ would\ write:\n\n\ \ glob\ /path/to/folder/*\n\nJust\ like\ in\ DOS,\ the\ first\ word\ of\ a\ Tcl\ statement\ is\ always\ a\ command.\ Simple\ isn't\ it?\n\nThe\ ''glob''\ command\ is\ just\ one\ of\ the\ commands\ available\ in\ Tcl.\ Another\ useful\ command\ is\ the\ ''puts''\ command.\ It\ simply\ prints\ things\ out\ on\ the\ screen.\ Try\ it:\n\n\ \ puts\ \"Hello\ World!\"\n\nYou\ may\ think\ of\ it\ as\ '''put'''\ '''s'''tring\ but\ I\ usually\ think\ of\ it\ as\ the\ plural\ of\ put\ (since\ it\ can\ output\ more\ than\ one\ character).\n\nNotice\ that\ ''puts''\ is\ similar\ to\ the\ ''echo''\ command\ in\ DOS\ and\ Unix\ shells.\ Again,\ this\ shows\ how\ simple\ Tcl\ is.\n\n'''Any\ Comments?..'''\n\nIn\ Tcl\ any\ command\ (first\ word\ in\ a\ statement)\ that\ begins\ with\ the\ '''#'''\ character\ is\ ignored.\ This\ is\ how\ one\ inserts\ comments.\ Comments\ are\ nice\ since\ they\ allow\ you\ do\ document\ things\ which\ may\ not\ be\ obvious\ in\ your\ code.\n\n\ \ \ #This\ is\ a\ comment\n\ \ \ #\ the\ Tcl\ interpreter\ will\ ignore\ comments\ so\ you\ can\ say\ whatever\ you\ like\ \;-)\n\n'''Variables\ and\ Values'''\n\nIn\ all\ programming\ languages,\ you\ use\ variables\ to\ store\ values.\ Some\ languages\ prevent\ you\ from\ storing\ different\ kinds\ of\ values\ into\ different\ kinds\ of\ variables.\ But\ we'll\ have\ none\ of\ that\ here.\ In\ Tcl\ a\ variable\ can\ hold\ anything\ (even\ complete\ programs\ if\ you\ want\ to).\ Variables\ will\ even\ hold\ your\ hand:\n\n\ \ set\ my_variable\ \"your\ hand\"\n\nwell..\ maybe\ not\ '''your'''\ hand,\ but\ the\ code\ above\ stores\ the\ string\ \"your\ hand\"\ into\ a\ variable\ called\ my_variable.\ The\ ''set''\ command\ is\ used\ to\ assign\ values\ to\ variables.\ It\ can\ also\ be\ used\ to\ get\ the\ value\ contained\ by\ the\ variable:\n\n\ \ #assign\ value:\n\ \ set\ new_var\ 100\n\n\ \ #get\ value\ and\ print\ it\ on\ screen\n\ \ puts\ \[set\ new_var\]\n\nProgrammers\ usually\ don't\ like\ typing\ too\ much.\ So\ Tcl\ provides\ a\ kind\ of\ shortcut\ to\ get\ the\ value\ of\ variables\ without\ using\ the\ ''set''\ command.\ Simply\ add\ a\ '''\$'''\ sign\ in\ front\ of\ the\ variable\ to\ get\ its\ value:\n\n\ \ #another\ way\ to\ get\ value\ of\ variables\n\ \ puts\ \$new_var\n\n\ \ #you\ can\ even\ assign\ values\ of\ other\ variables\ to\ a\ varaible:\n\ \ set\ my_variable\ \$new_var\n\nNotice\ that\ when\ one\ uses\ the\ ''set''\ command\ on\ a\ variable,\ one\ uses\ the\ variable\ without\ the\ '''\$'''\ sign.\ This\ is\ because\ the\ '''\$'''\ sign\ is\ not\ used\ to\ signify\ a\ variable\ like\ in\ Perl\ but\ is\ merely\ a\ shortcut\ for\ getting\ its\ value.\n\nJust\ for\ fun,\ what\ do\ you\ think\ happens\ in\ the\ following\ code?\n\n\ \ set\ foo\ \"this\ is\ cool\"\n\ \ set\ bar\ foo\n\ \ puts\ \[set\ \$bar\]\n\nIn\ the\ first\ statement,\ the\ variable\ ''foo''\ is\ set\ to\ hold\ the\ string\ ''\"this\ is\ cool\"''.\ The\ variable\ ''bar''\ is\ then\ set\ to\ the\ word\ ''\"foo\"''.\ Notice\ that\ there\ is\ no\ '''\$'''\ sign\ in\ front\ of\ ''foo''.\ This\ means\ that\ ''bar''\ is\ not\ assigned\ the\ '''value'''\ of\ ''foo''\ but\ just\ simply\ the\ word\ ''foo''.\n\nThe\ interesting\ part\ is\ the\ third\ statement.\ The\ ''set''\ command\ is\ used\ to\ get\ the\ value\ of\ ''\$bar''.\ Since\ ''bar''\ itself\ contains\ the\ word\ ''foo'',\ what\ happens\ is\ we\ get\ the\ value\ contained\ in\ the\ value\ of\ ''bar''.\ Confused?\n\nLet's\ examine\ the\ third\ line\ step\ by\ step.\ The\ '''\$'''\ sign\ is\ a\ shortcut\ to\ get\ the\ value\ of\ a\ variable.\ So\ ''\$bar''\ returns\ the\ word\ ''foo''.\ The\ ''set''\ command\ then\ gets\ the\ value\ of\ ''foo''\ and\ returns\ the\ string\ ''\"this\ is\ cool\"''.\ The\ third\ line\ can\ also\ be\ written\ as:\n\n\ \ puts\ \[set\ \[set\ bar\]\]\n\nbut\ writing\ ''\$\$bar''\ does\ not\ work.\ This\ is\ because\ '''\$\$'''\ is\ not\ something\ Tcl\ understands.\n\n'''Groupings'''\n\nThere\ are\ several\ things\ I\ did\ not\ explain\ in\ the\ examples\ above.\ One\ of\ which\ is\ the\ use\ of\ the\ double\ quotes\ (\").\ I\ know\ what\ you're\ thinking:\ I\ know\ that,\ it's\ a\ string.\ Correct...,\ but\ not\ quite.\ You\ see,\ in\ Tcl,\ everything\ is\ a\ string\ until\ it\ needs\ to\ be\ something\ else.\ Even\ 200\ is\ a\ string\ until\ you\ try\ to\ add\ 1\ to\ it.\ What\ the\ quotes\ represent\ in\ Tcl\ is\ grouping\ -\ a\ far\ simpler\ and\ powerful\ concept.\n\nLet's\ take\ a\ look\ at\ the\ ''set''\ command.\ It\ accepts\ either\ one\ or\ two\ parameters.\ If\ there\ are\ two\ parameters\ then\ the\ second\ parameter\ is\ a\ value\ to\ be\ assigned\ to\ the\ first\ parameter\ (which\ is\ a\ variable\ name).\ What\ if\ our\ string\ consists\ of\ more\ than\ one\ word?\ Trying\ to\ do:\n\ \ set\ foo\ this\ is\ cool\nwill\ result\ in\n\ \ error:\ wrong\ #\ args:\ should\ be\ \"set\ varName\ ?newValue?\"\nwhy?\ because\ we\ are\ given\ '''set'''\ four\ parameters,\ instead\ of\ two.\ we\ should\ write:\ \n\ \ set\ foo\ \"this\ is\ cool\"\n\n\nSo\ Tcl\ provides\ mechanisms\ to\ group\ words\ together.\ In\ the\ earlier\ example,\ foo\ is\ the\ first\ parameter\ and\ \"this\ is\ cool\"\ is\ the\ second,\ grouped\ by\ the\ quotes.\n\nTcl\ provides\ two\ ways\ to\ group\ things:\ the\ double\ quotes\ \"\ and\ curly\ braces\ \{\}.\ The\ above\ example\ would\ also\ work\ with:\n\n\ \ set\ foo\ \{this\ is\ cool\}\n\nWhat's\ the\ difference?\ Why\ two\ kinds\ of\ groupings?\ Well,\ things\ grouped\ with\ the\ double\ quotes\ will\ go\ through\ ''substitution''.\ Things\ grouped\ with\ braces\ will\ be\ left\ alone.\ You're\ saying\ what??..\ Lets\ see\ an\ example:\n\n\ \ set\ foo\ 100\n\ \ puts\ \{example1\ \$foo\}\n\ \ puts\ \"example2\ \$foo\"\n\nThe\ above\ code\ will\ print\ out:\n\n\ \ example1\ \$foo\n\ \ example2\ 100\n\nthat's\ because\ the\ first\ ''puts''\ statement\ is\ left\ alone\ while\ the\ second\ one\ is\ substituted.\n\n'''Substitution'''\n\nWe\ have\ seen\ one\ kind\ of\ substitution\ already.\ That\ is\ the\ '''\$'''\ shortcut.\ This\ is\ called\ ''variable\ substitution''\ because\ it\ replaces\ the\ variable\ with\ its\ value.\ Substitutions\ are\ what\ makes\ Tcl\ tick.\ It\ is\ a\ powerful,\ flexible\ and\ simple\ concept.\ There\ are\ three\ kinds\ of\ substitutions\ in\ Tcl:\ variable\ substitutions,\ command\ substitutions\ and\ backslash\ substitutions.\n\nWe\ have\ already\ seen\ variable\ substitution\ and\ it\ is\ explained\ above.\ It\ simply\ substitutes\ the\ value\ of\ the\ variable\ in\ place\ of\ the\ variable\ itself\ when\ a\ '''\$'''\ sign\ is\ added\ in\ front\ of\ the\ variable.\n\nCommand\ substitution\ is\ similar\ in\ that\ it\ substitutes\ the\ result\ of\ a\ command\ in\ place\ of\ the\ command.\ We\ have\ in\ fact\ already\ seen\ this\ above,\ but\ I\ did\ not\ explain\ it.\ Basically\ a\ statement\ between\ square\ brackets\ '''\[\[\ \]\]'''\ is\ treated\ as\ a\ command\ and\ is\ evaluated.\ The\ result\ is\ then\ substituted\ in\ its\ place.\ For\ example:\n\n\ \ set\ bat\ \"a\ list\ of\ files\ in\ the\ current\ directory:\ \[glob\ *\]\"\n\nThe\ glob\ command\ is\ evaluated,\ and\ its\ result\ is\ inserted\ into\ the\ string\ which\ is\ then\ assigned\ to\ the\ variable\ ''bat''.\ We\ have\ seen\ similar\ syntax\ in\ the\ various\ ''set''\ and\ ''puts''\ examples\ above.\n\nBackslash\ substitution\ is\ very\ similar\ to\ 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\nAlso,\ if\ a\ '''\\'''\ is\ followed\ by\ up\ to\ 3\ digits\ of\ numbers,\ than\ it\ is\ treated\ as\ an\ octal\ value\ for\ a\ character\ and\ the\ actual\ character\ is\ then\ substituted\ in\ its\ place.\n\nAny\ other\ character\ following\ a\ '''\\'''\ is\ replace\ with\ itself.\ This\ is\ an\ 'escape'\ mechanism\ that\ enables\ you\ to\ include\ special\ characters:\n\n\ \ puts\ \"This\ is\ how\ you\ print\ the\ double\ quote\ (\\\")\"\n\nIn\ addition,\ if\ a\ backslash\ '''\\'''\ appears\ at\ the\ end\ of\ a\ line,\ then\ that\ line\ continues\ on\ to\ the\ next\ line:\n\n\ \ puts\ \\\n\ \ \ \ \"Continued\ from\ the\ line\ above\"\n\nThis\ is\ to\ allow\ a\ long\ line\ of\ code\ to\ be\ split\ into\ multiple\ lines\ if\ you\ run\ out\ of\ space\ in\ your\ text\ editor.\n----\n\nSee\ also:\ http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm\n----\n'''What\ is\ a\ list?'''\n\nIn\ Tcl,\ everything\ is\ a\ string.\ But\ what\ is\ a\ list?\ It\ is\ basically,\ a\ string\ in\ which\ elements\ are\ separated\ by\ spaces.\nabout\ \[list%|%lists\],\ except\ that\ some\ command\ might\ interpret\ words\ passed\ to\ them\ as\n\ set\ a\ \"A\ B\ C\"\n\ lindex\ \$a\ 0\nset\ a\ \"A\ B\ C\"\n======none\n\ A\ B\ C\n\ A\nA\ B\ C\n\[lindex\]\ returns\ a\ list\ element,\ located\ at\ a\ given\ index.\ Indices\ start\ at\ 0.\nset\ command\ \{list\ \{*\}\{one\ two\ three\}\}\n\ set\ a\ \{A\ B\ C\}\n\ lindex\ \$a\ 1\n\nreturns\ \"B\".\nB\n--\ \[Sarnold\]\ 2005/11/27\n\n----\n\n\[JM\]\ slebetman:\ I\ would\ like\ to\ participate\ in\ this\ page,\ I\ can\ suggest\ an\ idea\ that\ I\ think\ fits,\ then\ if\ you\ agree\ I\ can\ insert\ the\ text\ where\ I\ think\ it\ belongs,\ so\ I\ don't\ mess\ original\ idea\ of\ this\ page.\n\nexample:\nfor\ the\ \"any\ comments?\"\ section,\ we\ can\ include\ that,\ a\ common,\ alternative\ way\ to\ insert\ comments\ in\ tcl\ (and\ I\ think\ not\ just\ in\ tcl)\ is\ by\ means\ of:\n\ if\ \{0\}\ \ \{these\ are\ the\ comments\}\nwhich\ is\ really\ code\ that\ is\ never\ executed.\n\n\[slebetman\]\ I'd\ wait\ until\ we\ introduce\ the\ 'if'\ command.\ I\ know\ '''if'''\ is\ obvious\ to\ anyone\ who\ is\ used\ to\ programming\ in\ any\ language.\ But\ I\ want\ to\ impress\ the\ ''essence\ of\ Tcl''\ to\ newbies.\ Mixing\ syntax\ and\ command\ is\ not\ good\ in\ my\ view.\n\nBut\ thanks\ for\ your\ support.\ Please\ edit\ away\ any\ mistakes\ that\ you\ find\ here.\ But\ please\ refrain\ from\ commenting\ ''in-line''.\ Comment\ at\ the\ bottom.\ In-line\ comments\ in\ the\ text\ itself\ is\ to\ be\ considered\ transient\ and\ may\ be\ edited\ away\ once\ corrections\ are\ made.\n\nAlso,\ if\ you\ find\ ways\ to\ re-phrase\ sentences\ and\ paragraphs\ in\ a\ more\ 'friendly'\ manner,\ please\ do\ so\ (in-line\ comments\ may\ be\ appropriate\ in\ this\ case\ if\ there\ is\ no\ consensus\ yet).\ I\ want\ to\ keep\ the\ tone\ of\ this\ introduction\ fun,\ friendly\ and\ informal,\ sort\ of\ like\ for-dummies,\ maybe\ even\ more\ fun.\ Humor\ is\ very\ much\ encouraged\ but\ not\ at\ the\ expense\ clarity:\ fun,\ not\ flippant.\n\nAnyway,\ I\ think\ the\ syntax\ rules\ are\ covered.\ Feel\ free\ to\ start\ describing\ commands\ like\ '''if''',\ '''proc'''\ etc.\ Don't\ worry\ about\ which\ comes\ before/after\ which.\ We\ can\ always\ edit\ and\ re-arrange\ chapters\ later.\n\n\[Lars\ H\],\ 28\ november\ 2005:\ Well,\ there's\ no\ mention\ of\ \\x\ and\ \\u\ substitution.\ I\ find\ \\u\ interesting\ to\ mention,\ since\ it\ points\ to\ the\ fact\ that\ Tcl\ is\ not\ restricted\ to\ 8-bit\ characters,\ which\ however\ many\ other\ languages\ are.\n\n\[slebetman\]\ Good\ catch.\ Missed\ that.\ I'll\ be\ adding\ it\ later\ when\ I\ have\ time.\ Or\ you\ are\ free\ to\ do\ it\ yourself.\n\n''\[escargo\]\ 28\ Nov\ 2005''\ -\ I\ don't\ like\ spoiling\ the\ fun,\ but\ I\ think\ it's\ worthwhile\ mentioning\ some\ of\nthe\ \"gotchas\"\ of\ Tcl.\ \ For\ example,\ that\ comments\ require\ balanced\ delimiters,\ that\ commands\ that\ take\n''similar''\ parameters\ don't\ necessarily\ take\ ''identical''\ parameters\ (that\ is,\ some\ things\ can\ be\ more\nirregular\ than\ other\ languages\ because\ there\ isn't\ an\ overarching\ grammar\ that\ enforces\ regularity).\n\n''\[AET\]\ 29nov05''\ I\ agree,\ but\ there\ are\ many\ places\ where\ such\ information\ interrupts\ the\ learning\ flow.\ \ A\ simple\ '''DO'''\ and\ '''DONT'''\ list\ is\ less\ confusing\ for\ a\ beginner.\ \ And\ please,\ PLEASE\ resist\ the\ temptation\ (that\ so\ many\ have\ fallen\ to)\ to\ describe\ a\ new\ subject\ in\ terms\ of\ ''Here's\ some\ code\ that\ doesn't\ work,\ and\ here's\ why\ \ .\ .\ ''.\ \ A\ beginner\ needs\ to\ see\ and\ absorb\ simple,\ clear\ and\ above\ all\ CORRECT\ code.\ \ Please\ also\ keep\ debate\ of\ finer\ points\ of\ style,\ completeness,\ unusual\ exceptions\ etc.\ to\ other\ pages.\n\n\[slebetman\]\ I\ agree\ with\ \[AET\].\ I\ intend\ to\ give\ new\ users\ the\ 'feel'\ of\ Tcl\ which\ I\ and\ a\ lot\ of\ others\ found\ lacking\ in\ \[TCL\ programs\ for\ beginners\ 1-10\].\ This\ is\ meant\ as\ an\ introduction,\ not\ a\ complete\ description.\ By\ the\ way,\ I\ always\ wondered\ why\ the\ matching\ bracket\ thing\ is\ not\ documented\ in\ the\ 11\ rules\ of\ Tcl:\ http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm\n\nAlso,\ with\ regards\ to\ wiki\ rules\ about\ editing\ other's\ post.\ If\ the\ changes\ in\ the\ comments\ are\ implemented,\ can\ I\ delete\ the\ comment?\ Also,\ I\ hope\ others\ won't\ mind\ if\ I\ later\ re-arrange\ parts\ of\ this\ page\ to\ make\ it\ more\ coherent\ overall.\n\n\[Lars\ H\]:\ The\ \"no\ unmatched\ braces\ in\ comments\"\ restriction\ is\ only\ relevant\ in\ bodies\ (of\ \[proc\],\ \[foreach\],\ \[while\],\ etc.),\ so\ it\ is\ natural\ to\ bring\ up\ in\ that\ context,\ but\ this\ is\ too\ early\ --\ there\ hasn't\ yet\ been\ any\ example\ where\ a\ comment\ with\ an\ unmatched\ brace\ would\ spoil\ anything!\n----\n'''DO'''\n\n\ \ \ *\ Learn\ how\ to\ use\ `\[exec\]`\ so\ that\ you\ can\ start\ using\ Tcl\ to\ drive\ external\ programs\n----\n'''DON'T'''\n\ \ \ *\ Don't\ have\ unmatched\ brackets\ ANYWHERE,\ including\ comments.\ \ Use\ a\ text\ editor\ that\ helps\ you\ by\ showing\ bracket\ matching.\ \ \n\ \ \ *\ Don't\ expect\ to\ use\ an\ array\ in\ a\ proc\ till\ you\ understand\ 'upvar'.\ \ \n\ \ \ *\ Don't\ expect\ to\ drive\ external\ programs\ easily\ till\ you\ get\ the\ hang\ of\ 'exec'.\ \ \n----\n'''ESPECIALLY\ USEFUL\ TCL\ FEATURES'''\n\ \ \ *\ \[foreach\]\ is\ wonderful.\ \ Simple\ and\ powerful.\ \ \n----\n'''Code\ reusing\ and\ packaging'''\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\ \ \ *\ Do\ split\ your\ code\ into\ different\ \[namespace\]s\ (and\ files)\ when\ it\ overcomes\ ca.\ a\ thousand\ lines.\n\n----\n'''Regarding\ Variables\ and\ Values\ example'''\n\ \ set\ foo\ \"this\ is\ cool\"\n\ \ set\ bar\ foo\n\ \ puts\ \[set\ \$bar\]\n\ \ puts\ \[set\ \[set\ bar\]\]\nyet\ another\ line\ to\ add\ to\ example\ code:\n\ \ puts\ \[expr\ \$\$bar\]\n\n\[Lars\ H\]:\ I\ don't\ think\ that\ would\ be\ a\ good\ idea,\ because\ \[\[expr\ \$\$bar\]\]\n\[Lars\ H\]:\ I\ don't\ think\ that\ would\ be\ a\ good\ idea,\ because\ \[\[expr\ \$\$bar\]\]\ combines\ two\ bad\ habits\ for\ a\ Tcl\ programmer:\ not\ bracing\ \[expr\]essions\ and\ \$\ signs\ that\ fail\ to\ substitute.\ It\ can\ at\ best\ be\ a\ specimen\ for\ illuminating\ some\ of\ the\ odd\ quirks\ of\ the\ language,\ but\ it\ is\ definitely\ not\ something\ beginners\ should\ be\ exposed\ to.\n----\n\nSee\ also,\ \"\[The\ first\ article\ to\ read\ about\ Tcl\]\".\n----\n\[Category\ Tutorial\]} CALL {my revision {TCL for beginners}} CALL {::oo::Obj66021 process revision/TCL+for+beginners} CALL {::oo::Obj66019 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