[erlang-questions] What is wrong with this list?

Dustin Sallings dustin@REDACTED
Wed Sep 5 01:37:20 CEST 2007


On Sep 4, 2007, at 15:26 , Peter K Chan wrote:

> As someone who has known Erlang for a while, the error message  
> would probably not be helpful (if even possible). But as a newbie,  
> knowing the difference between an assignment and a match can be  
> very helpful. Actually, if the bad match comes from some deep  
> recursion, I think I would appreciate seeing the actual value, even  
> if I know what badmatches in general are.
>
> I do agree that the current error message gives out enough  
> information for debugging purpose, but having seen, more than once,  
> where someone is confused about the matching vs. assignment, I  
> think the more explicit error message would be "nice" to have.

	I'm not arguing that it can't be better, I'm just suggesting that it  
might not be as simple as saying ``x != y'' as there are a lot of  
other cases where a badmatch may occur where that wasn't the intention.

	In the particular example I gave, it might be wrong because I  
accidentally used the same variable name twice, or it might be wrong  
because the function returned invalid results.  It could be tricky to  
produce an error that helps solve each problem.

	It might be good enough to just format the error better in logs and  
shells.  e.g. instead of

{{badmatch,[x]},[{erl_eval,expr,3}]}

	something like:

bad match:  The following value was not expected here:  [x]
   {erl_eval,expr,3}

	It means the same thing, but might help people understand it a  
little better.  Then again, that could make it harder to know how to  
catch errors since it's no longer obvious that I can also match  
against {badmatch, X}.

-- 
Dustin Sallings





More information about the erlang-questions mailing list