[erlang-questions] Local namespaces in case/try
Ivan Uemlianin
ivan@REDACTED
Tue Jul 10 12:20:44 CEST 2012
On 10/07/2012 11:10, Dmitry Groshev wrote:
> 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.
In erlang it seems that they are bound:
http://www.erlang.org/course/advanced.html#scope
http://www.erlang.org/doc/reference_manual/expressions.html#id75881
> ... I'm sorry
> but I can't see why do you think that that values should be identical.
I am only a beginner.
Ivan
>
> 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 <mailto:ivan@REDACTED>
> www.llaisdy.com <http://www.llaisdy.com>
> llaisdy.wordpress.com <http://llaisdy.wordpress.com>
> github.com/llaisdy <http://github.com/llaisdy>
> www.linkedin.com/in/ivanuemlianin
> <http://www.linkedin.com/in/ivanuemlianin>
>
> "hilaritas excessum habere nequit"
> (Spinoza, Ethica, IV, XLII)
> ============================================================
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
> http://erlang.org/mailman/listinfo/erlang-questions
> <http://erlang.org/mailman/listinfo/erlang-questions>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
--
============================================================
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)
============================================================
More information about the erlang-questions
mailing list