Assertions in strategies
I think it would be helpful if rules / strategies could have some kind of assertion mechanism that generates a useful error message.
Just now, for example, I used “unions” instead of “union”. “unions” requires a list of lists, whereas “union” takes a tuple with two lists in it. If there were some sort of “assert” mechanism that added a custom message to the resulting failure, one could insert that assertion into the “union” and “unions” strategies and instead of a generic “with clause failed” you might get something like “Expected a tuple in union” or “Expected a list in unions”.
This would be useful for my own strategies as well - I could put in some assertions.
Currently I seem to be inserting a lot of trace statements and making educated guesses about the problem, which is less than ideal.
Submitted by Dobes Vandermeer on 30 October 2012 at 20:27
Issue Log
There is an assert mechanism: with(s|“message”)
When the strategy application of
s
fails, “message” is printed. The downside is that it causes a fatal exception and analysis stops, and this cannot be turned off.
I guess that’s basically what I was looking for. Although, it’s “fatality” approach might not work for all strategies, in cases like “union” vs “unions” it seems like this should be OK as the programmer has obviously made a mistake.
Log in to post comments