Erlang uses the underscore atom (in single quotes) quite a lot. See for instance here.

MatchExpression ::= [ MatchFunction, ... ]
MatchFunction ::= { MatchHead, MatchConditions, MatchBody }
MatchHead ::= MatchVariable | '_' | [ MatchHeadPart, ... ]
MatchHeadPart ::= term() | MatchVariable | '_'

and it seems to wig out your wiki-style display. So this is a straight paragraph with the offending item '_' in it and it looks super-fine-dandy in the preview when I am writing it but blows up when I submit.

(There's no way to test this except by submitting and the bug failed to appear here so I have put it back in the StackOverflow comment where it happened which I had worked around. So you can see it there - the big italic block after the 5th code snippet).

  • sorry, but I don't see where the problem is. can you clarify? everything in your example looks fine. – Kyle Cronin Jul 15 '09 at 8:24
  • Yeah it doesn't show up here - but it does in my Stackoverflow comment I link to. The line '' or ignore the return value should not show italicised it should be '_' or ignore the return value. – Gordon Guthrie Jul 15 '09 at 9:24
  • I have now posted the original that shows the bug down the answer tree and it adds display a second bug :( – Gordon Guthrie Jul 15 '09 at 11:35
  • not seeing the problem, sorry.. – Jeff Atwood Jul 16 '09 at 17:27

I see what you mean (on the original post), and indeed the preview seemed fine (there are a few other gotchas between preview and actual).

In the post, I changed it to:


which fixed it; but lets see if it '_' happens here when I post this... nope - worked fine; very curious.


**In order to make this bug fixable I will quote the complete text that caused the problem here. It seems to be quite hard to reproduce :(

The original post on StackOverflow has kindly been worked-around/fixed by Marc Gravell.**

OK, first define the function:

printEven(I,N) when I >= N -> ok;
printEven(I,N)             -> 
    I rem 2 == 0 -> io:format("~p~n",[I]), printEven(I+1,N);
    I rem 2 == 1 -> printEven(I+1,N)

Erlang is a functional programming language and (by definition) functions 'have' a value so you are going to get 'something' back. By convention the thing you get back on completion of a function that you are using for side-effects is the atom 'ok', that's the best to use here.

You can 'silently discard' the return value if you want. You do that when you invoke the function by pattern matching to the 'don't care' variable (which is underscore):

_ = printEven(3,9),

or by calling the function without a pattern match:


However, you are much better to always check return values by pattern matching when you invoke a function:

ok = printEven(3,9),

This is a a really good habit to get into because you will be using a lot of library functions that return error codes as you can see from their specs:

@spec funky(X) -> [ok | {error, bad_op} | {error, wig_out}]

If funky has side effects you want to know it has failed now by invoking it with a pattern match so it will crash here and now if funky fails:

ok = funky(99),

If you match it to '_' or ignore the return value it will crash 268 lines later when your mojo expects funky to have done his thang, and then it is much harder to find.

This is happy path programming which is the done thing in Erlang. "Let it crash" is the motto. If you are new to Erlang you will find this very disconcerting - like walking about naked. Don't worry embrace it, it is a good thing. It leads to lots of code 'not being written'.

(You should also get in the habit of putting the clause that ends the recursion as the top clause as shown here - it makes reading the code sooo much easier when you have a multi-clause function.)

  • Meta-bug! I win. Notice that the initial text of this bug (the explanatory text I added) has been set in bold but displays with it escaped. I'm giving up :( – Gordon Guthrie Jul 15 '09 at 11:34
  • you can't cross paragraphs with bold. That's not a bug.. see the Markdown spec, or editing help: meta.stackoverflow.com/editing-help – Jeff Atwood Jul 17 '09 at 4:25
  • Umm, it shows as bold in the preview... – Gordon Guthrie Jul 18 '09 at 17:22

This was fixed at some point. Neither preview nor final version of your post have the top in bold (which is the correct behavior, as Jeff explained).

And the preview and the final version also have the same behavior regarding your '_'. In this page it still looks broken because the post is still rendered as it was five years ago, but if you look at what it would be rendered like today, you'll see it's correct. If an edit were made to your answer now, forcing it to be rerendered, that's what you would see on this very page as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .