[erlang-questions] Pass a pattern to a function

Michael McDaniel <>
Tue Feb 10 19:43:29 CET 2009


 not sure if it will help you, but possibly of interest in the
 Erlang docs, 

  Basic Applications -> erts -> Erts Users Guide -> Match specifications

~M

 


On Tue, Feb 10, 2009 at 07:18:59PM +0100, Jachym Holecek wrote:
> Hello,
> 
> # Sten Gruener 2009-02-10:
> > I try to write a function to scan the message queue and discard matched
> > messages.
> > 
> > Like this:
> > 
> > discard(Pattern) ->
> >     receive
> >         Pattern ->
> >             discard(Pattern)
> >     after 0 ->
> >         ok
> >     end.
> > 
> > the problem is, that I cannot call discard({_, {msg}}) since _ is a wildcard
> > representation. Are there any solutions?
> 
> Patterns aren't first class objects so I'm afraid you're SOL. You could
> implement your discard/1 as a parse transform, but under the hood that
> would just create per-pattern-specialised discard functions. Alternatively,
> it would be doable with a macro, but I can't imagine that not being ugly.
> 
> 	-- Jachym
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions

-- 
Michael McDaniel
Portland, Oregon, USA
http://autosys.us




More information about the erlang-questions mailing list