List comprehension bug?
    James Hague 
    jamesh@REDACTED
       
    Thu Mar 20 16:37:46 CET 2003
    
    
  
I posted this last month, but it was buried inside of another thread, so
here's another shot :)
You get a bizarre runtime error and no compile time warnings if you don't
bind a variable on the right side of a list comprehension.  For example,
take the standard definition of map:
map(F, [H|T]) ->
    [F(H)|map(F, T)];
map(_, []) -> [].
and change it to:
map(F, [H|T]) ->
    [F(H)||map(F, T)];
map(_, []) -> [].
I did this by accident once, and it took me half an hour to see the typo.
You get an runtime error report indicating that a case expression couldn't
be matched, but I would think this code shouldn't get through the compiler
in the first place.  Or is there a reason to allow list comprehensions with
a single predicate on the right side?
James
    
    
More information about the erlang-questions
mailing list