[erlang-questions] why can't _ be passed around?

Matthias Lang matthias@REDACTED
Thu Sep 22 14:08:41 CEST 2011


Idle curiosity: why can't I pass or send _? 

I can write:

  f() ->
    receive _ -> ok
    after 500 -> exit(timeout) end.

But I can't write

  g(Pattern) ->
    receive Pattern -> ok
    after 500 -> exit(timeout) end.

  f() ->

Nor can I write

  f() ->
    g({my_atom, 3, _}).

Ok, I realise I'm not allowed to because _ isn't bound. But _ can't
ever be bound (right? or is there another way of thinking about _?).

I've written g/1 as a macro. There doesn't seem to be a catch.

Thoughts? Am I asking for patterns to be first class? Whoever wrote
ets:match() must have had a similar train of thought.


More information about the erlang-questions mailing list