[erlang-questions] Pass a pattern to a function

Robert Virding <>
Tue Feb 10 20:35:03 CET 2009


Yes, but match specs can only be used in ETS and in tracing, they are not a
general purpose construction. Basically they are a normal Erlang data
structure which is interpreted in a special way by ETS and the tracer.

Robert

2009/2/10 Michael McDaniel <>

>
>  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
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090210/cc6bc780/attachment.html>


More information about the erlang-questions mailing list