Skip to content
Tcl Source Code Artifact [583fadfcf9]
Login

Artifact [583fadfcf9]

Artifact 583fadfcf9eda0b2edea8fdb6fade0a4d02782e7defb5edb7b47fed6a28a5b9d:

Ticket change [583fadfcf9] - Ticket [b204c13b2b2335a6|b204c13b2b] <i>Incompatibility between 8.6 and 8.7 with underscores in numerics</i> status still Open with 3 other changes by juliannoble2 on 2023-08-27 13:28:25.
D 2023-08-27T13:28:25.799
J icomment If\sthis\sis\sto\sbe\sa\sdocumentation\sissue\s-\sthen\sI\sthink\ssome\sclarification\sof\sthe\sintended\susage\sand\sbest\spractice\sis\srequired.\r\n\r\nTIP\s551\sis\svery\slight\son\sdetails\sabout\swhat\sthe\sintention\sis\sregarding\s'in\ssource\scode'\swhen\sit\scomes\sto\sa\slanguage\slike\sTcl\swhich\sis\sfundamentally\sdifferent\sto\sothers.\r\nThere\sis\snotably\sno\s'consequences'\sor\s'compatibility'\ssection\sin\sthe\sTIP.\r\n\r\nWhile\sthe\sissues\smight\sat\sfirst\sseem\sthe\ssame\sas\sper\s0x\s0b\s0d\s0f\sspecifiers\sthere\sare\sa\scouple\sof\sdifferences.\r\n\r\n1)On\sa\spossibly\sminor\snote\s-\sthe\sunderscore\scross-cuts\sall\sthese\sas\sit\sextends\sthe\ssyntax\sof\sthem\sall.\r\nThis\scan\spresumably\sbe\saddressed\sin\scompatibility\sdocumentation\sbut\salready\sprevious\scode\slooking\sat\sleading\s0x\sand\sthen\sdoing\sa\s[string\sis\sxdigit]\son\sthe\sremainder\swould\sneed\supdating..\sas\spresumably\swould\ssome\sregexs.\r\n\r\n2)\sThe\sdistinction\sbetween\swhat\sis\ssource\scode\svs\sdata\sis\sless\sclear\sin\sTcl.\sAs\sit\sseems\sthere\sis\sno\sintention\sto\srestrain\sthis\ssyntax\sto\sexpr\sstatements\swhere\sit\sis\snormalized\s-\sthe\sstring\srep\sis\sfree\sto\spropagate\sto\sother\slibraries/areas\sof\sthe\scodebase\sunless\sexplicit\ssteps\sare\staken.\r\n\r\nIt's\sclear\sfrom\ssome\sof\sthe\stest\sfiles\sand\sfrom\sinteractive\suse\sthat\sthe\sextended\snumeric\ssyntaxes\swork\sin\sother\scommands\ssuch\sas\sthe\slist\sand\sstring\scommands\swhether\sas\sliterals\sin\sthe\sspecific\sline\sof\ssource\sor\sas\sresults\sof\scommand\sor\svariable\ssubstitution.\r\n\r\nThere\sis\san\sexample\sin\ssocket.test\sof:\s\s\s\s\s\sset\sport\s0x7fffffff\r\n(It's\stolerated\sjust\sfine\sby\ssocket\s-\sand\ssimilarly\sother\schannel\scommands\ssuch\sas\sread\saccept\sa\ssize\swith\svarious\sformats)\r\n\r\nThis\sleads\sone\sto\sassume\sthat\ssimilarly\s'set\sport\s6_000'\s\setc\sare\slikely\sto\sbe\slooked\son\sfavourably\sby\scoders\sand\sa\sthis\spoint\s-\swith\sserialization\sand\sconfiguration\ssaving\s-\sthe\ssyntax\sis\sinevitably\sgoing\sto\sup\sin\sconfig\sfiles\sor\sat\sthe\svery\sleast\sinitialisation\sdefaults.\sMore\slikely\sso\sI\ssuspect\sthan\sthings\slike\s0xFF\sor\s0b1010,\sthough\sultimately\sthe\sissues\sare\ssimilar.\r\n\r\nMy\spoint\sis\snot\sso\smuch\swhether\sthis\sis\sa\sbad\sthing\sas\ssuch\s-\sbut\sthat\sthe\spolicy\sof\swhat\sis\sintended\sis\sunclear\s-\sand\sthe\sconsequences\sof\sthis\s'leakage'\sare\sapparent\sfrom\sa\ssomewhat\shaphazard\ssurvey\sI've\sdone\sof\sthe\sbehaviour\sof\svarious\slibraries\s(mainly\sin\stcllib).\sSee\sbelow.\r\n\r\nIf\sit's\sintended\sto\sbe\sgenerally\slimited\sin\ssome\sway\s-\sthen\sperhaps\sdocumentation\sshould\sexpress\sa\spreference\sfor:\r\nset\sport\s[expr\s{6_000}]\s\s\s\r\n\r\nBut\sthis\sof\scourse,\swhilst\sstill\sproviding\sclarity\sfor\sreading\slarger\snumbers,\sremoves\ssome\sof\sthe\sconvenience\sfactor\sthe\sfacility\swas\sintended\sto\sintroduce.\r\n(It\salso\sdoesn't\swork\sin\sall\ssituations\swhere\sfor\sexample\snormalising\s6_000.00\s\sto\s6000.0\smay\sbe\san\sundesirable\sloss\sof\sprecision)\r\n\r\n\r\nIs\sit\sintended\sthat\susage\ssuch\sas:\r\nproc\smyfunc\s{{maxsize\s6_000_000}}\s{...}\r\nset\smyval\s3_000.000_001\r\n\r\nwhere\sthe\svalues\sare\slater\spotentially\spassed\sto\sother\slibraries\sthat\sdocument\sthey\saccept\sintegers\sor\sdoubles\s-\sbe\snormal\susage?\s\r\n\r\nIf\sso\s-\sthen\sall\sthese\slibraries\sand\sexisting\scode\sbases\sneed\sto\sproperly\snormalize\sor\sotherwise\sdo\sfurther\schecks\sthan\sjust\s'string\sis\sinteger|double\s-strict'\sif\sthey\sare\snot\susing\sthem\spurely\sas\snumbers.\r\n\r\nThe\sissue\swith\sthings\slike\sport\s6_000\sbeing\sloaded\sfrom\sconfigs\sor\sdefaults\s-\sis\snot\sthat\sthere\sis\sa\sproblem\spassing\sit\son\sto\sthe\ssocket\scode\s-\sbut\sthat\sconfiguration\ssettings\ssuch\sas\sthese\sare\squite\slikely\sto\sbe\sfed\sto\sother\sparts\sof\scode\swhere\sit's\streated\sas\sa\sstring.\r\ne.g\shypothetically:\s\sset\sconnectioninfo\s${ip}_${serverport}_${clientport}\s\r\n\r\nNow\simagine\sanother\spart\sof\sthe\scode\ssplitting\sthat\son\s_\sto\swork\sout\sthe\sports.\sAll\sfixable\swith\sdocumentation\sand\sguidelines\sI'm\ssure,\sbut\sI\sthink\sthe\snotes\sin\sthe\sproc\sbelow\sgive\san\sidea\sof\sthe\spotentially\shidden/latent\snature\sof\sthis.\sIt\sgives\sthe\spotential\sfor\sexisting\scodebases\sto\sbecome\sunreliable\sas\swider\suse\sof\sthe\ssyntax\soccurs.\s\r\n\r\n\r\nproc\shandle_input\s{input}\s{\r\n\s\s\s\sif\s{[string\sis\sdouble\s-strict\s$input]}\s{\r\n\r\n\r\n\s\s\s\s\s\s\s\s##1)\s-\sa\sgeneric\sexample/comment\r\n\s\s\s\s\s\s\s\slassign\s[split\s$input\s.]\sa\sb\r\n\s\s\s\s\s\s\s\sif\s{[regexp\se\s$b]}\s{\r\n\s\s\s\s\s\s\s\s\s\s\s\s#return\s[handle_input_sci\s$input]\r\n\s\s\s\s\s\s\s\s}\r\n\s\s\s\s\s\s\s\s##custom\scode\srelated\sto\ssigfigs,currency(treating\sinput\sas\sstring\sto\sbe\sconverted\sto\ssome\snon-float)\sor\ssome\sother\spurpose\sthat\suses\s$a\sand\s$b\r\n\s\s\s\s\s\s\s\s##\sany\scode\susing\sstring\slength\sto\sanalyze\sthe\scomponents\swill\sneed\sto\sbe\saware.\r\n\s\s\s\s\s\s\s\s##note\sthat\sa\sand\sb\scan\sno\slonger\sbe\sassumed\sto\spass\sthe\sstring\sis\sdouble\s-strict\stest\sindependently\r\n\s\s\s\s\s\s\s\s##e.g\sfor\sinput\s1000_._01\s\swhich\spasses\sthe\sinitial\stest\s\swe\sget\s1000_\s\sand\s_01\s\swhich\sdon't.\r\n\s\s\s\s\s\s\s\s##\sThis\smay\sbe\sunlikely\sinput\sbut\sthe\s1_._0\s\sappears\sto\sbe\svalid\sdouble\ssyntax\sas\sfar\sas\sTcl\sis\sconcerned.\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##2)\sa\ssample\staken\sfrom\sthe\swiki\r\n\s\s\s\s\s\s\s\s##https://wiki.tcl-lang.org/page/significant+digits+rounding\r\n\s\s\s\s\s\s\s\s#puts\sstdout\s[signif\s$input\s6\s.]\r\n\s\s\s\s\s\s\s\s##error:\snumber\sto\sround\s"1_000.1234"\sis\snot\snumeric\r\n\s\s\s\s\s\s\s\s##\sin\sfairness\s-\sthis\scode\sdoesn't\shandle\s0x\s0b\s0o\s0d\s\seither\s-\s\r\n\r\n\s\s\s\s\s\s\s\s##3)\r\n\s\s\s\s\s\s\s\s##Breaks\ssilently!\s\s\s\s\r\n\s\s\s\s\s\s\s\s##from\stcllib\smath::decimal\s-\s(ticket\screated\s2023-08)\r\n\s\s\s\s\s\s\s\s##\swhen\sinput\shas\sunderscore\son\srhs\se.g\s1.000_001\r\n\s\s\s\s\s\s\s\s#package\srequire\smath::decimal\r\n\s\s\s\s\s\s\s\s#math::decimal::compare\s[math::decimal::fromstr\s1.000001]\s[math::decimal::fromstr\s$input]\r\n\s\s\s\s\s\s\s\s##\sreturns\s1\swhen\sshould\sbe\s0\r\n\s\s\s\s\s\s\s\s##\s(rescale\suses\sstring\slength)\r\n\s\s\s\s\s\s\s\s##\scompare\s1\svs\s0d1\s,\s0x0_2\svs\s0b1_0\setc\swork\sok.\r\n\s\s\s\s\s\s\s\s##However\s-\sfrom\spostings\son\swiki.tcl.tk\sby\sthe\sauthor\sMark\sAlston\s-\sit\sappears\sthe\sintended\sinput\sformat\sis\sas\sspecified\sin\sthe\sIEEE\s754\sstandard\sgiven\sat\shttp://speleotrove.com/decimal/\si.e\snumeric\sstrings\r\n\s\s\s\s\s\s\s\s##\sConsequently\sit\smay\sbe\sworthwhile\smodifying\sthe\stcllib\sversion\sto\sexplicitly\scheck\sthe\sinput\sconforms\srather\sthan\sallowing\sTcl's\salternate\snumber\sforms\sto\sleak\sinto\sit\s-\ssometimes\sworking,\sor\ssometimes\sfailing\ssilently\sor\snoisily.\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##4)\r\n\s\s\s\s\s\s\s\s##tcllib\s\r\n\s\s\s\s\s\s\s\s#package\srequire\smath::bigfloat\r\n\s\s\s\s\s\s\s\s##Failure\sinput\sexample\s1_000.25\r\n\s\s\s\s\s\s\s\s#puts\sstdout\s[math::bigfloat::fromstr\s$input]\r\n\s\s\s\s\s\s\s\s##error:\s1_000.25\sis\snot\sa\snumber\r\n\s\s\s\s\s\s\s\s##Nor\sdoes\sbigfloat's\sfromstr\saccept\s0x,\s0b\s\setc\s\r\n\s\s\s\s\s\s\s\s##\r\n\s\s\s\s\s\s\s\s##-\sthis\sis\sat\sodds\swith\smath::decimal::fromstr\swhich\sdoes,\sbut\sperhaps\sby\shappenstance\smore\sthan\sby\sdesign.\r\n\s\s\s\s\s\s\s\s##-\sdocumentation\sof\sthe\sfromstr\smethods\sshould\sspecify\sexplicitly\sif\salternate\sformats\sallowed\sand\slib\sshould\ssanitize/reject\sif\snot\srather\sthan\saccept\ssome\sand\snot\sothers.\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##5)\r\n\s\s\s\s\s\s\s\s##tcllib\smath::bignum\r\n\s\s\s\s\s\s\s\s#package\srequire\smath::bignum\r\n\s\s\s\s\s\s\s\s##Failure\sinput\sexample\s1_000\r\n\s\s\s\s\s\s\s\s#puts\sstdout\s[math::bignum::fromstr\s$input]\r\n\s\s\s\s\s\s\s\s##error:\sIllegal\schar\s'_'\sfor\sbase\s10\r\n\s\s\s\s\s\s\s\s##-\sas\sabove\s-\sbignum's\sfromstr\sacceps\s0d\s0x\sbut\snot\s1_000\sor\s0d1_000\s-\sinconsistent\swith\smath::bigfloat\sand\smath::bigdecimal\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##6)\r\n\s\s\s\s\s\s\s\s##tcllib\s-\sThe\sunits\smodule\stakes\sstrings\s-\sso\sit\scan't\sbe\sexpected\sto\saccept\sthe\snew\sformat,\r\n\s\s\s\s\s\s\s\s##\showever\s-\sthis\smay\sbe\scalled\sfrom\suser\scode\sthat\sdoes\stake\snumbers\sas\sparameters\r\n\s\s\s\s\s\s\s\s##\sand\shas\sonly\schecked\s'string\sis\sinteger'\sor\s'string\sis\sdouble'\sand\sbuilt\sa\sstring\sto\spass\son\sto\sunits::convert\r\n\s\s\s\s\s\s\s\spackage\srequire\sunits\r\n\s\s\s\s\s\s\s\s##works\sfor\s2100,\s2.1e3\s\r\n\s\s\s\s\s\s\s\sunits::convert\s"${input}m"\skm\s\r\n\s\s\s\s\s\s\s\s##\sFailure\sinput\sexample\s2_100\s\r\n\s\s\s\s\s\s\s\s##error:\sinvalid\scharacters\sin\sunit\sstring\s'2_100m'\r\n\s\s\s\s\s\s\s\s##Units\squite\sreasonably\sdoesn't\saccept\s0x\s0b\s0d\setc\seither\s-\sThe\sdifference\sbeing\sthe\squestion\sof\swhether\snumbers\slike\s1_000\sare\smore\slikely\sto\sleak\soutside\sof\splain\sexpr\susage\sto\svariables\sthroughout\sthe\scode/serialized\sdata.\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##7)\r\n\s\s\s\s\s\s\s\s##tcllib\s\r\n\s\s\s\s\s\s\s\s#package\srequire\sascii85\r\n\s\s\s\s\s\s\s\s#ascii85::encode\s-maxlen\s$input\s"somestring....\s"\s\r\n\s\s\s\s\s\s\s\s##\sFailure\sinput\sexample\s1_00\r\n\s\s\s\s\s\s\s\s##error:\sCouldn't\scompile\sregular\sexpression\spattern:\sinvalid\srepetition\scount(s)\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##8)\r\n\s\s\s\s\s\s\s\s##tcllib\r\n\s\s\s\s\s\s\s\s#package\srequire\sstruct::pool\r\n\s\s\s\s\s\s\s\s##\sfailure\sinput\sexample\s1_000\r\n\s\s\s\s\s\s\s\s#struct::pool\smypool\s$input\r\n\s\s\s\s\s\s\s\s##error:\sThe\ssecond\sargument\smust\sbe\sa\spositive\sinteger\svalue\r\n\s\s\s\s\s\s\s\s##\s(regexp\son\smaxsize)\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s\s\s\s\s##9)\r\n\s\s\s\s\s\s\s\s##\stcllib\sstruct::prioqueue\r\n\s\s\s\s\s\s\s\s##\sworks\sfine\swith\svarious\sunderscored\spriorities\s-\sbut\sthey\spop\sout\sthe\sother\sside\sin\squeuename\speekpriority\r\n\s\s\s\s\s\s\s\s##\s-\sThis\smay\sbe\smore\sof\sa\sfeature\sthan\sa\sbug\s-\sbut\san\sexample\sof\swhere\sthe\seffects\smay\slie\sdistant\sto\swhere\sa\sdefault\swas\sset,\r\n\s\s\s\s\s\s\s\s##\se.g\sin\slogging/debugging\scode.\r\n\s\s\s\s\s\s\s\s\r\n\s\s\s\s}\selse\s{\r\n\s\s\s\s\s\s\s\sputs\sother-branch\r\n\s\s\s\s\s\s\s\s#return\s[handle_input_nondouble\s$input]\r\n\s\s\s\s}\r\n}\r\n\r\nAll\sthis\sis\sto\ssay,\sI\sthink\sreleasing\sthis\sis\sa\sbold\schoice\sfor\sa\snon-major\sversion\sbump\s-\sand\sI'm\shoping\sthat\ssomeone\swith\sexperience\scan\sprovide\ssome\smore\sclarity/code-review\sguidance\sin\sboth\sthe\sTIP\sdocumentation\sand\sany\srelease-notes\sor\sgeneral\sTcl\sguidelines.
J login juliannoble2
J mimetype text/plain
K b204c13b2b2335a6baf8fa1a3c6a627432380012
U juliannoble2
Z d950ace9e60cb1f977470f8c397425db