Problem with bit syntax compilation

Daniel Néri dne@REDACTED
Mon Apr 16 19:00:55 CEST 2001


"Jouni Ryno" <jouni.ryno@REDACTED> writes:

> error(Test) ->
>     if
> 	Test == 1 ->
> 	    Problem = 1;
> 	Test == 2 ->
> 	    Problem = 2
>     end,
>     Dummy = 1,
>     OKbin = <<Test:7, Dummy:9>>,    % used only to prove, that it works 
> normally
>     MyBin = [<<Test:7, Problem:9>>, OKbin].
> 
> I get compilation error from erlc test.erl (eshell V5.0.2

Although it does look like a bug, you missed the warning:

  /tmp/test.erl:12: Warning: variable 'Problem' exported from 'if' (line 4)

So instead try:

   ,----
   | error(Test) ->
   |     Problem = if
   |                   Test == 1 ->
   |                       1;
   |                   Test == 2 ->
   |                       2
   |               end,
   |     Dummy = 1,
   |     OKbin = <<Test:7, Dummy:9>>,
   |     MyBin = [<<Test:7, Problem:9>>, OKbin].
   `----


Regards,
   --Daniel

-- 
Daniel Neri
dne@REDACTED



More information about the erlang-questions mailing list