variable '_' is unbound

Fredrik Linder fredrik.linder@REDACTED
Tue May 28 19:48:42 CEST 2002


> I's like to be able to cover both cases inn the same clause.

Then why not extract the code in the function clause into a new function,
and keep the two clauses in foo?

foo(bar) ->
    extracted_foo_clause();
foo(<< _ : 3, 1 : 1, _:12 >>) ->
    extracted_foo_clause().

extracted_foo_clause() ->
    ...  % Same ... as below ;-)

In this way you both solve your two-clauses-that-cannot-be-written-as-one
problem and you'll get a shorter foo/1 function, which is good. :-) But do
come up with a better name!

/Fredrik

> Other wise I'm just making two copies of a large chunk of
> code which is both wasteful and error prone.
>
> What I really have is:
>
> foo(bar) ->
> ...
> foo(<<_:3, 1:1, _:12>>) ->
> ...
>
> So I tried:
>
>    foo(Arg) when bar == Arg; <<_:3, 1:1, _:12>> == Arg ->
>
>
> I reallu just need to test one bit in the middle of this binary.
> I guess I need a strategy that doesn't require binding a variable.
>
> -Vance
>




More information about the erlang-questions mailing list