Skip to content
Tcl Source Code Artifact [6db2c7794d]
Login

Artifact [6db2c7794d]

Artifact 6db2c7794d9f7a8c9f9499e5d9e4d2abb1d4d837661ac1660a1392907b7da31e:

Tag referencing [6db2c7794d] - Edit [1508c3d76ada99be|1508c3d76a]: Edit check-in comment. by Florentis on 2026-11-05 09:31:42.
D 2026-11-05T09:31:42.165
T +comment 1508c3d76ada99be76eda49f86311191497abcf8353e1ff0c99040117059778b Version\s16p\sadds\sa\sfield\sto\sthe\s`Proc`\sstructure.\nIt\sallows\sfor\sthe\styping\sof\sboth\sthe\sreturn\svalue\sand\sthe\sarguments\sof\sprocedures.\sExample:\n\ntcl\nproc\s{pt}decale\s{\n\s\s\s\s{pt}p;\s\n\s\s\s\s{double}dx\s?=\s0;\s\n\s\s\s\s{double}dy\s?=\s0\n}\s{\n\s\s\s\sset\s{pt}q\s[expr\s{$p(x)\s+\s$dx}]\s[expr\s{$p(y)\s+\s$dy}]\n\s\s\s\sreturn\s$q\n}\nset\s{pt}a\s1\s2\ndecale\s$a\s1\s1\s\s\s\s\s\s\s\s\s\s;#\spositional\ndecale\s$a\s{dy:}5\s\s\s\s\s\s\s;#\spositional,\sfollowed\sby\slabels\ndecale\s{dy:}5\s{p:}$a\s\s\s;#\slabels\sonly,\sin\sany\sorder\n\nArguments\n\nFields:\sEach\sfield\sbecomes\sa\slocal\svariable\ssubject\sto\sits\sdefined\scontract.\nDefaults:\s`?=\sv`\sor\s`?=\s[cmd]`—evaluated\sat\seach\sprocedure\scall;\sit\smay\sreference\spreceding\sfields.\nRemainder:\sA\sfinal\sfield,\s`{list.T}args`,\scollects\sany\sexcess\sarguments,\seach\sof\swhich\sis\svalidated.\nAutomatic\s`upvar`:\s`{var.T}n`\sbinds\s`n`\sto\sa\svariable\sin\sthe\scallers\sscope,\swith\sits\scurrent\svalue\sbeing\svalidated.\nCall-site\slabels:\sPositional\sarguments\sfollowing\sa\slabel\sare\sdisallowed;\sproviding\sthe\ssame\sfield\stwice\sor\susing\san\sunknown\slabel\swill\salso\sresult\sin\san\serror.\sException:\sIf\sthe\starget\sfield\sis\sa\ssum\stype,\sthe\slabel\sselects\sthe\sspecific\svariant\s(e.g.,\s`ps\s{s:}abc`).\nMessages:\sThese\stake\sforms\ssuch\sas\s`wrong\s#\sargs:\sshould\sbe\s"decale\sp\s?dx?\s?dy?"`\sor\s`argument\s"dx":\sexpected\sfloating-point\snumber\sbut\sgot\s"abc"`.\n\nReturn\sValue\n\nCast:\s`proc\s{T}name`\scasts\sthe\sresult\sof\sa\sstandard\s`return`\sto\stype\s`T`.\sErrors,\s`break`,\s`return\s-level\s2`,\s`tailcall`,\sand\s`yield`\sare\snot\ssubject\sto\sthis\scast.\nLocal\sannotation:\s`return\s{U}$x`\ssimply\sattaches\san\sannotation,\swhich\sexpires\swhen\sthe\sprocedure\sterminates.\sThere\sis,\stherefore,\sno\stype\soverlapping\s(or\s"cumulation"\sof\stypes).\nTags:\sWhen\sa\sreturn\svalue\sis\sa\ssum\stype,\s`return\s{point:}$z`\sselects\sthe\sspecific\svariant,\sand\sa\sstrict\ssum\stype\s(`-strict`)\smandates\sit.\sUsing\sa\stag\sthat\sis\snot\sa\svalid\svariant,\sor\sapplying\sone\sto\sa\sreturn\svalue\sthat\sis\snot\sa\ssum\stype,\sresults\sin\san\serror.\n\nIntrospection\sand\scompatibility\n\n`type\sproc\sname\sreturns\sargs\s{…}\sreturn\sT`—`info\sargs`\sand\s`info\sdefault`\scan\s"see"\sthe\sfields.\nA\svalid\sTcl\slist\sremains\sa\sstandard\slist\sof\sarguments.\sAn\sinitial\sattempt\scaused\sthe\s`proc-old-5.4`\stest\sto\sfail\s(due\sto\san\sunclosed\sbrace);\sthis\shas\sbeen\sfixed,\sand\sthe\sstandard\serror\sis\snow\scorrectly\sreturned.\n\nPerformance\scost:\sA\scall\swith\s3\sarguments\stakes\s1.2\sµs,\scompared\sto\s0.6\sµs\sfor\san\sequivalent\sstandard\sprocedure.\sThe\sreturn-type\scast\sincurs\sno\soverhead\sif\sthe\svalue\sis\salready\sof\sthe\scorrect\stype.\n\nSee\snext\scommit\sfor\scomplements
U Florentis
Z 74341a3d9a1ac40b5d11cd07eabfe9c1