Tag times in is protected что за ошибка
How do I identify the source of a «Tag times protected» error?
I have some code that looks like
which gives an error:
In this case, it is quite clear that there is a semicolon missing after b = <2, 3>, which is causing this error. However, sometimes I encounter this in large code blocks spanning several lines, which is very difficult to debug.
How can I automate this semicolon hunting to make debugging easier?
4 Answers 4
Here is a function findBadSets that will find any explicitly bad Set / SetDelayed attempts in a given expression. Simply wrap it around a syntactically complete block of code, or follow the block with // findBadSets and the errors are printed one per row, protected symbol followed by complete left-hand side for each bad Set:
Code for the function:
One can use Trace for this. I stuck in an extra, different error to show it is omitted in the output. It should also be clear how to trace other error messages.
If you would like a function like Mr.Wizard’s to apply to a code block, we can wrap it up like this:
Now you can see the offending code comes from
If it’s a very large chunk of code, you can select the bottom segment of the evaluation chain as follows. The length of the chain is controlled by
which can be adjusted to suit:
One could also apply the OpenerView to each element in the output by adding to the pattern in the second argument of Cases the code :> ov[e, True] to make it a transformation rule.