unsafe variables in try?

Mark Scandariato mscandar@REDACTED
Mon Oct 25 22:11:07 CEST 2004


The compiler complains that X and R are unsafe:

     split(Bin, N) ->
         try <<X:N/unit:8, R/binary>> = Bin
         case
             error:badarg -> throw(format)
         end,
         {X, R}.

Is there any way to get it to accept the above code?

This, of course, works (but but seems otherwise needless):

     split(Bin, N) ->
         try split2(Bin, N)
         case
             error:badarg -> throw(format)
         end.

     split2(Bin, N) -> <<X:N/unit:8, R/binary>> = Bin.


It'd be really nice if this worked:

     split(N, <<X:N/unit:8, R/binary>>) -> {X, R};
     split(_, _) -> throw(format).


Thanks,
Mark.



More information about the erlang-questions mailing list