[erlang-questions] Local namespaces in case/try

Ivan Uemlianin <>
Tue Jul 10 11:54:11 CEST 2012


> On 07/10/2012 10:43 AM, Dmitry Groshev wrote:
> case do_something() of
>      {ok, Result} -> Result;
>      {error, Error} -> Error
> end,
> case do_another() of
>      {ok, Result} -> Result;
>      {error, Error} -> Error
> end,
>
> Result and Error are bound in first case and we will probably have a
> match failure in second one. Compiler warns about this, but it's still
> very unwieldy to fix it with names like Error1, Error2, etc.

Are you expecting that the "Result" variable returned from do_another() 
should have the same value as the "Result" returned from do_something()? 
  (and likewise for Error.)

If so, I don't see why you would get a match failure: e.g., you surely 
wouldn't get a match failure if do_something() and do_another() both 
returned {ok, 5}?

If not, yes you will get match failures.

To this naive observer, the code looks like the "Result"s (and the 
"Errors"s) are expected to be identical.

Best wishes

Ivan


-- 
============================================================
Ivan A. Uemlianin PhD
Llaisdy
Speech Technology Research and Development

                     
                      www.llaisdy.com
                          llaisdy.wordpress.com
               github.com/llaisdy
                      www.linkedin.com/in/ivanuemlianin

               "hilaritas excessum habere nequit"
                  (Spinoza, Ethica, IV, XLII)
============================================================





More information about the erlang-questions mailing list