Skip to content
Tcl Source Code Artifact [5de805bca6]
Login

Artifact [5de805bca6]

Artifact 5de805bca68104f56038eb7c871974618f3c20c7:

Ticket change [5de805bca6] - Ticket [959147ffffffffff|959147ffff] <i>Restore sanity to variable name resolution</i> status still Open with 6 other changes by msofer on 2014-09-29 00:26:36.
D 2014-09-29T00:26:36.461
J closer nobody
J comment There\sis\sa\sfundamental\sproblem\swith\svarName\sresolution\r\nin\snamespaces.\sThe\svariable\slookup\sis\sas\sfollows:\s\r\n(1)\slookup\sin\sthe\scurrent\snamespace;\sif\sthe\svar\sexists,\r\nreturn\sa\sref\r\n(2)\slookup\sin\sthe\sglobal\snamespace;\sif\sthe\svar\sexists,\r\nreturn\sa\sref\r\n(3)\sif\sthe\svar\shas\sto\sbe\screated,\screate\sit\sin\sthe\r\nlocal\snamespace\r\n\r\nQuite\sapart\sfrom\sthe\sdifficulty\sof\sdefining\swhat\sit\r\nmeans\sfor\sa\svariable\sto\sexist\s(see\sBug\s#959052),\sthis\r\nbehaviour\sis\ssurprising\sand\sdangerous.\s\r\n\r\nA\ssimple\svariable\scall\smay\srefer\sto\sa\sns-local\sor\r\nglobal\svariable,\sunder\scircumstances\sthat\sare\sdifficult\r\nto\scheck,\sand\swhich\smay\svary\sdepending\son\snon-local\sissues.\r\n\r\nnamespace.n\sdefines\sthe\srule\sas:\s\r\n"Command\sand\svariable\snames\sare\salways\sresolved\sby\r\nlooking\sfirst\sin\sthe\scurrent\snamespace,\sand\sthen\sin\sthe\r\nglobal\snamespace.\sNamespace\snames,\son\sthe\sother\shand,\r\nare\salways\sresolved\sby\slooking\sin\sonly\sthe\scurrent\r\nnamespace."\r\n\r\nThat\sthe\sprocess\sfor\svariables\sis\sblack\smagic\sis\r\nactually\simplicit\sin\sthat\sman\spage:\s"You\scan\suse\sthe\r\nnamespace\swhich\scommand\sto\sclear\sup\sany\squestion\sabout\r\nname\sresolution."\sBut\sthere\sis\sno\shint\sof\sthe\sfragility\r\nof\sthe\sprocedure\swith\srespect\sto\sthe\sexistence\sof\sthe\r\nglobal\svariable,\sespecially\sfor\s"creative\swriting"\s-\r\nie,\screating\sa\svariable\sand\ssetting\sits\svalue\sat\sthe\r\nsame\stime.\r\n\r\nNote\sthat\scommands\sdo\snot\shave\sthis\screative\swriting\r\nproblem:\s[proc]\salways\screates\sthe\scommand\sin\sthe\r\ncurrent\snamespace\sif\sthe\sname\sis\sunqualified.\r\n\r\nThis\sRFE\sproposes\sthat\swe\ssimplify\sthe\svarName\r\nresolution\srule\sin\snamespaces\sso\sthat\sit\sis\salways\r\nsimple\sand\spredictable,\sjust\sas\sit\sis\sfor\svarName\r\nresolution\sin\sproc\sbodies.\sThe\snew\sdescription\swould\sbe:\r\n\r\n"Command\snames\sare\salways\sresolved\sby\slooking\sfirst\sin\r\nthe\scurrent\snamespace,\sand\sthen\sin\sthe\sglobal\r\nnamespace.\sNamespace\sand\svariable\snames,\son\sthe\sother\r\nhand,\sare\salways\sresolved\sby\slooking\sin\sonly\sthe\r\ncurrent\snamespace."
J icomment To\sillustrate\sthe\sproblem,\sconsider:\r\n\r\n%\sset\sa\s0\r\n0\r\n%\snamespace\seval\sx\s{set\sa\s1;\sset\sb\s1}\r\n1\r\n%\sset\sa\r\n1\r\n%\sset\sb\r\ncan't\sread\s"b":\sno\ssuch\svariable\r\n%\sset\sx::a\r\ncan't\sread\s"x::a":\sno\ssuch\svariable\r\n%\sset\sx::b\r\n1
J login msofer
J mimetype text/plain
J severity Minor
K 959147ffffffffffffffffffffffffffffffffff
U msofer
Z d7d426bc3fcc002b066c83deb9fa6639