Skip to content
Tcl Source Code Artifact [36a6d6a787]
Login

Artifact [36a6d6a787]

Artifact 36a6d6a787dd4b1514aaa85ca4d4c8c9c53f9676:

Ticket change [36a6d6a787] - New ticket [959147ffffffffff|959147ffff] <i>Restore sanity to variable name resolution</i>. by msofer on 2004-05-23 23:28:31.
D 2004-05-23T23:28:31
J assignee msofer
J cmimetype text/plain
J comment There\sis\sa\sfundamental\sproblem\swith\svarName\sresolution\nin\snamespaces.\sThe\svariable\slookup\sis\sas\sfollows:\s\n(1)\slookup\sin\sthe\scurrent\snamespace;\sif\sthe\svar\sexists,\nreturn\sa\sref\n(2)\slookup\sin\sthe\sglobal\snamespace;\sif\sthe\svar\sexists,\nreturn\sa\sref\n(3)\sif\sthe\svar\shas\sto\sbe\screated,\screate\sit\sin\sthe\nlocal\snamespace\n\nQuite\sapart\sfrom\sthe\sdifficulty\sof\sdefining\swhat\sit\nmeans\sfor\sa\svariable\sto\sexist\s(see\sBug\s#959052),\sthis\nbehaviour\sis\ssurprising\sand\sdangerous.\s\n\nA\ssimple\svariable\scall\smay\srefer\sto\sa\sns-local\sor\nglobal\svariable,\sunder\scircumstances\sthat\sare\sdifficult\nto\scheck,\sand\swhich\smay\svary\sdepending\son\snon-local\sissues.\n\nnamespace.n\sdefines\sthe\srule\sas:\s\n"Command\sand\svariable\snames\sare\salways\sresolved\sby\nlooking\sfirst\sin\sthe\scurrent\snamespace,\sand\sthen\sin\sthe\nglobal\snamespace.\sNamespace\snames,\son\sthe\sother\shand,\nare\salways\sresolved\sby\slooking\sin\sonly\sthe\scurrent\nnamespace."\n\nThat\sthe\sprocess\sfor\svariables\sis\sblack\smagic\sis\nactually\simplicit\sin\sthat\sman\spage:\s"You\scan\suse\sthe\nnamespace\swhich\scommand\sto\sclear\sup\sany\squestion\sabout\nname\sresolution."\sBut\sthere\sis\sno\shint\sof\sthe\sfragility\nof\sthe\sprocedure\swith\srespect\sto\sthe\sexistence\sof\sthe\nglobal\svariable,\sespecially\sfor\s"creative\swriting"\s-\nie,\screating\sa\svariable\sand\ssetting\sits\svalue\sat\sthe\nsame\stime.\n\nNote\sthat\scommands\sdo\snot\shave\sthis\screative\swriting\nproblem:\s[proc]\salways\screates\sthe\scommand\sin\sthe\ncurrent\snamespace\sif\sthe\sname\sis\sunqualified.\n\nThis\sRFE\sproposes\sthat\swe\ssimplify\sthe\svarName\nresolution\srule\sin\snamespaces\sso\sthat\sit\sis\salways\nsimple\sand\spredictable,\sjust\sas\sit\sis\sfor\svarName\nresolution\sin\sproc\sbodies.\sThe\snew\sdescription\swould\sbe:\n\n"Command\snames\sare\salways\sresolved\sby\slooking\sfirst\sin\nthe\scurrent\snamespace,\sand\sthen\sin\sthe\sglobal\nnamespace.\sNamespace\sand\svariable\snames,\son\sthe\sother\nhand,\sare\salways\sresolved\sby\slooking\sin\sonly\sthe\ncurrent\snamespace."\n\n\n\n\n\n
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter msofer
J subsystem 07.\sVariables
J title Restore\ssanity\sto\svariable\sname\sresolution
J type RFE
K 959147ffffffffffffffffffffffffffffffffff
U msofer
Z fcb2fd606140a1939c5907d3f171e338