Skip to content
Tcl Source Code Artifact [9551919225]
Login

Artifact [9551919225]

Artifact 9551919225e73c5e8b8c23a8d86c83a198ff56a2:

Ticket change [9551919225] - New ticket [1143805fffffffff|1143805fff] <i>Impurity of empty [list]</i>. by lars_h on 2005-02-18 13:59:28.
D 2005-02-18T13:59:28
J assignee dkf
J cmimetype text/plain
J comment A\scomment\son\sthe\sTcler's\sWiki\spage\son\s[concat]\s(http://wiki.tcl.tk/\n1037)\smade\sme\saware\sof\sthe\sfact\sthat\sthe\sresult\sof\s[list]\sis\snot\s\nalways\sa\spure\slist;\sthe\sresult\sof\s[list]\swhen\scalled\swithout\s\narguments\sis\srather\san\sempty\sstring.\sThis\sdifference\scan\sbe\sseen\s\non\sthe\sscript\slevel\sas\sfollows:\n\n%\sset\sthird\s[expr\s1.0/3]\n0.333333333333\n%\sexpr\s{$third*3}\n1.0\n%\sexpr\s{[lindex\s[concat\s[list\s$third]\s[list\sx]]\s0]*3}\n1.0\n%\sexpr\s{[lindex\s[concat\s[list\s$third]\s[list]]\s0]*3}\n0.999999999999\n\nIn\sthe\ssecond\scase,\sthe\ssecond\sargument\sof\s[concat]\sis\snot\sa\spure\s\nlist,\sand\sthus\s[concat]\soperates\son\sits\sarguments\sin\sstring\smode,\s\nforcing\sa\sloss\sof\sthe\sinternal\srepresentation\sof\sthe\sthird.\n\nThe\sbug\sis\sthus:\sThe\sresult\sof\s[list]\sis\snot\salways\sa\spure\slist.\n\nNow,\sif\sanyone\swants\sto\sargue\sthat\sthis\sis\snot\sa\sbug,\sthen\sI\scan't\s\nreally\sobject;\ssince\severything\sis\s(or\sat\sleast\sshould\sbe)\sa\sstring,\s\nand\sin\sparticular\san\sempty\slist\sis\sthe\ssame\sthing\sas\san\sempty\s\nstring,\sTcl_ListObjCmd\sis\scompletely\sright\swhen\sit\ssimply\sleaves\s\nthe\sempty\sresult\sin\sthe\sinterpreter.\sJudging\sfrom\sthe\sway\sit\sis\s\nwritten,\sthis\sis\seven\sby\sdesign:\n\nint\nTcl_ListObjCmd(dummy,\sinterp,\sobjc,\sobjv)\n\s\s\s\sClientData\sdummy;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sNot\sused.\s*/\n\s\s\s\sTcl_Interp\s*interp;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sCurrent\sinterpreter.\s*/\n\s\s\s\sregister\sint\sobjc;\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s/*\sNumber\sof\sarguments.\s*/\n\s\s\s\sregister\sTcl_Obj\s*CONST\sobjv[];\s\s\s\s\s/*\sThe\sargument\sobjects.\s*/\n{\n\s\s\s\s/*\n\s\s\s\s\s*\sIf\sthere\sare\sno\slist\selements,\sthe\sresult\sis\san\sempty\sobject.\n\s\s\s\s\s*\sOtherwise\sset\sthe\sinterpreter's\sresult\sobject\sto\sbe\sa\slist\s\nobject.\n\s\s\s\s\s*/\n\n\s\s\s\sif\s(objc\s>\s1)\s{\n\s\s\s\s\s\s\s\sTcl_SetObjResult(interp,\sTcl_NewListObj((objc-1),\s\n&(objv[1])));\n\s\s\s\s}\n\s\s\s\sreturn\sTCL_OK;\n}\n\nOTOH,\sthe\sdistinction\sbetween\sarbitrary\slists\sand\spure\slists\sis\s\nsomething\sthat\smany\sprogrammers\stake\scare\sto\sobserve,\sbecause\s\nof\sthe\sefficiency\simprovements\sthis\scan\sbring,\sand\sthen\sit\sseems\sa\s\nbit\sodd\sthat\sall\sreturn\svalues\sfrom\s[list]\s_except_\sthe\sempty\sone\s\nshould\sbe\spure.\sThis\scan\slead\sto\sstrange\seffects\sin\scases\slike\n\n\s\s\sset\sextraOpts\s[list]\n\s\s\sforeach\sopt\s{-foo\s-bar\s-baz}\s{\n\s\s\s\s\s\sif\s{[needOption\s$opt]}\sthen\s{lappend\sextraOpts\s$opt}\n\s\s\s}\n\s\s\seval\s[list\ssomeCmd\s$someHugeDataStructure]\s$extraOpts\n\nwhere\sthe\s[eval]\ssuddenly\stakes\smuch\smore\stime\swhen\sno\sextra\s\noptions\sare\spassed,\ssince\s$extraOpts\swill\sthen\snot\sbe\sa\spure\slist.\n\nAlso,\sI\soften\sfind\smyself\swriting\n\n\s\s\sset\sres\s[list]\n\nrather\sthan\n\n\s\s\sset\sres\s{}\n\nprecisely\sbecause\sI\sknow\sthat\sthis\swill\sbe\sa\slist\sand\swant\sto\s"speed\s\nthings\sup"\sby\sinitialising\sto\san\sobject\swith\sa\slist\srepresentation,\sand\s\nI\sam\snot\sthe\sonly\sone\swho\sdoes\sthis\s--\s"set\ssomeVar\s[list]"\sis\squite\s\ncommon\son\sthe\sWiki.\sIt\snow\sturns\sout\sthat\sthis\sis\sin\svain,\ssince\s\nwhat\s[list]\sreturns\sactually\sdoesn't\shave\sa\slist\srepresentation!
J foundin obsolete:\s8.4.9
J priority 5\sMedium
J resolution None
J status Open
J submitter lars_h
J subsystem 17.\sCommands\sI-L
J title Impurity\sof\sempty\s[list]
J type Bug
K 1143805fffffffffffffffffffffffffffffffff
U lars_h
Z 24b1ed7a3991b7eb3c7dffd996b13cfd