Skip to content
Tcl Source Code Artifact [0cc52de499]
Login

Artifact [0cc52de499]

Artifact 0cc52de4996350c55f7d8f3c1a0f8233466cbaad:

Ticket change [0cc52de499] - New ticket [550789ffffffffff|550789ffff] <i>[break] should take an &quot;after&quot;-script</i>. by nobody on 2002-04-30 21:28:32.
D 2002-04-30T21:28:32
J assignee dkf
J cmimetype text/plain
J comment It\swould\sbe\svery\sconvenient\sif\sone\scould\ssupply\sto\sbreak\s\na\sscript\sthat\swill\sbe\sevaluated\safter\sthe\sloop\scommand\s\nthat\sthe\s[break]\sis\sbreaking\shas\sended,\sbut\sbefore\sthe\s\nfirst\scommand\safter\sit.\sThis\scould\sbe\sused\sto\sbreak\sout\s\nof\snested\sloops:\n\nforeach\si\s{a\sb\sc\sd}\s{\n\s\s\sforeach\sj\s{a\sb\sc\sd}\s{\n\s\s\s\s\s\sset\sfoo\s[bar\s$i\s$j]\n\s\s\s\s\s\sif\s{$foo<3}\sthen\s{\n\s\s\s\s\s\s\s\s\sbreak\s{break}\n\s\s\s\s\s\s}\n\s\s\s\s\s\s#\sSome\smore\sprocessing\n\s\s\s}\n\s\s\s#\sbreak\sin\sbreak-script\swould\sbe\sevaluated\shere\n\s\s\sincr\ssum\s$foo\s;\s#\sSome\sstill\smore\sprocessing\n}\n\nor\sto\sbreak\sout\sof\san\sinner\sloop\sand\simmediately\s\ncontinue\sto\sthe\snext\siteration\sof\san\souter:\n\nfor\s{set\si\s0}\s{$i<$i_max}\s{incr\si}\s{\n\s\s\sfor\s{set\sj\s0}\s{$j<$j_max}\s{incr\sj}\s{\n\s\s\s\s\s\sif\s{[try_it\s$i\s$j]}\sthen\s{\n\s\s\s\s\s\s\s\s\sset\sT($i)\s$j\n\s\s\s\s\s\s\s\s\sbreak\s{continue}\n\s\s\s\s\s\s}\n\s\s\s}\n\s\s\s#\scontinue\sin\sbreak-script\swould\sbe\n\s\s\s#\sevaluated\shere\n\s\s\sputs\sstdout\s"No\ssolution\sfound\sfor\si=$i."\n}\n\nTo\sbreak\sout\sof\sthree\snested\sloops,\sone\swould\ssimilarly\s\ngive\sthe\scommand\n\nbreak\s{break\s{break}}\n\nIn\swant\sof\sthis\sfeature,\sI\shave\slately\sfound\smyself\s\nmaking\svery\sfrequent\suse\sof\sauxiliary\svariables,\sso\sthat\s\nthe\sfirst\sexample\swould\sinstead\shave\sbeen\n\nset\sbreaking\s0\nforeach\si\s{a\sb\sc\sd}\s{\n\s\s\sforeach\sj\s{a\sb\sc\sd}\s{\n\s\s\s\s\s\sset\sfoo\s[bar\s$i\s$j]\n\s\s\s\s\s\sif\s{$foo<3}\sthen\s{\n\s\s\s\s\s\s\s\s\sset\sbreaking\s1\n\s\s\s\s\s\s\s\s\sbreak\n\s\s\s\s\s\s}\n\s\s\s\s\s\s#\sSome\smore\sprocessing\n\s\s\s}\n\s\s\sif\s{$breaking}\sthen\s{break}\n\s\s\sincr\ssum\s$foo\s;\s#\sSome\sstill\smore\sprocessing\n}\n\nwhich\sis\smuch\sless\selegant\s(and\sno\sdoubt\sslower).\sMaking\s\nspecial\sprocedures\sfor\sloops\sthat\sI\sneed\sto\sbreak\sout\sof\s\n(so\sthat\sI\scan\suse\s[return]\sinstead)\shelps\sin\ssome\s\ncases,\sbut\sis\snot\salways\sappropriate.\n\nAs\sfar\sas\sthe\simplementation\sis\sconcerned,\sthis\sdoes\snot\s\nseem\sparticularly\scomplicated.\sSince\sno\smore\sthan\sone\s\n[break]\scan\sbe\sgoing\son\sat\sany\ssingle\stime,\sthe\s\ninterpreter\snever\sneeds\sto\skeep\strack\sof\smore\sthan\sone\s\nbreak-script.\sIn\sprinciple,\sall\sthe\s[break]\scommand\s\nwould\shave\sto\sdo\swould\sbe\sto\sset\ssome\svariable\s(perhaps\s\na\sglobal\svariable\s"breakScript",\sto\sgo\swith\s"errorInfo"\s\nand\s"errorCode"?)\sto\sthe\sbreak-script.\sThen\sthe\slooping\s\ncommands\sneed,\swhen\sthey\scatch\sa\sTCL_BREAK\sreturn,\sonly\s\nlook\sat\sthis\svariable\sto\ssee\sif\sthere\sis\sa\sspecial\s\nscript\sto\sevaluate\sor\snot.\sEven\smore\sstreamlined\swould\s\nbe\sto\shave\sa\s[break]\swith\sa\sscript\sargument\sreturn\ssome\s\nnew\scode,\ssay,\sTCL_BREAK_SCRIPT\sinstead\sof\sTCL_BREAK.\n\nSome\snotes:\n\n1.\sSince\sbreak-scripts\scan\smake\sTCL_BREAK\sand\s\nTCL_CONTINUE\sreturns,\sthey\sappearently\sreturn\sa\sresult.\s\nThis\scan\sbe\sused\sto\shave\s[for],\s[foreach],\sand\s[while]\s\nreturn\sa\snon-empty\sresult:\n\nset\si_pos\\\n\s\s[foreach\si\s$some_list\s{\n\s\s\s\s\s\sif\s{$A($i)>0}\sthen\s{break\s{set\si}}\n\s\s\s}]\n\nwill\sset\s$i_pos\sto\sthe\sfirst\s$i\sfor\swhich\s$A($i)>0,\sor\s\nto\san\sempty\sstring\sif\sthere\swas\sno\ssuch\s$i.\sIn\sthe\scase\s\nof\s[for],\sthis\swould\snot\sadd\sany\sextra\sfunctionality\s\nsince\sa\sseparate\s[set\si]\scommad\safter\sthe\s[for]\swould\s\nhave\spretty\smuch\sthe\ssame\seffect,\sbut\sin\sthe\scase\sof\s\n[foreach]\sit\sallows\sone\sto\sdistinguish\sbetween\snot\s\nfinding\sanything\sand\sfinding\ssomething\son\sthe\slast\s\niteration.\n\n2.\sProcedure\sbodies\sand\sthe\s[catch]\scommand\salso\scatch\s\nTCL_BREAK\sreturns;\show\sshould\sthey\sreact\sto\sbreak-\nscripts\sthen?\sIn\sthe\scase\sof\sprocedure\sbodies,\s\nevaluating\s[break]\sis\snormally\san\serror,\sso\sthere\sis\sno\s\nneed\sto\sreact\sto\sthe\sbreak-script\sat\sall.\sIn\sthe\scase\sof\s\ncatch\sthere\sis\ssimilarly\sno\sneed\sto\sevaluate\sthe\sbreak-\nscript,\sas\sthe\scode\s[catch]ing\smight\swant\sto\sinspect\sit\s\n(just\sas\swith\s$errorCode);\sthis\sis\swhy\sit\swould\smake\s\nsense\sto\sput\sthe\sscript\sin\sa\svariable\sthat\sis\saccessible\s\nfrom\sTcl.\n\n3.\sThe\smechanism\sproposed\sabove\shave\smany\ssimilarities\s\nto\sthe\sTCL_EVAL\sreturn\scode\ssuggested\sin\sTIP\s#90.\sIt\sis\s\nprobably\sbest\streated\sin\sconjuction\swith\sthat.\n\n/Lars\sHellström\n
J foundin None
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 16.\sCommands\sA-H
J title [break]\sshould\stake\san\s"after"-script
J type RFE
K 550789ffffffffffffffffffffffffffffffffff
U nobody
Z a742f71d7e1d0b020c1b9e3929d911fe