[erlang-questions] Local namespaces in case/try

Dmitry Groshev lambdadmitry@REDACTED
Tue Jul 10 12:10:45 CEST 2012


Ivan,

There is a concept called "lexical scoping" — it means that some lexical 
constructs have a local namespace. In that example I would expect that all 
variables that were introduced inside case statement (Error/Result) won't 
be bound after the statement. On top of that, Erlang compiler already has 
some similar logic — it will warn you about "exported" variables and will 
not compile code with "unsafe" variables, so it's only a matter of a minor 
(and maybe optional) language change. I'm sorry but I can't see why do you 
think that that values should be identical.

On Tuesday, July 10, 2012 1:54:11 PM UTC+4, Ivan Uemlianin wrote:
>
> > 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 
>
>                      ivan@REDACTED 
>                       www.llaisdy.com 
>                           llaisdy.wordpress.com 
>                github.com/llaisdy 
>                       www.linkedin.com/in/ivanuemlianin 
>
>                "hilaritas excessum habere nequit" 
>                   (Spinoza, Ethica, IV, XLII) 
> ============================================================ 
>
>
> _______________________________________________ 
> erlang-questions mailing list 
> erlang-questions@REDACTED 
> http://erlang.org/mailman/listinfo/erlang-questions 
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120710/81e7c670/attachment.htm>


More information about the erlang-questions mailing list