Behaviour was clear to me (and logic). My doubt is: why elixir force me to put a "useless" else clause and lowering readability?
On Thursday, July 14, 2016 at 5:17:10 PM UTC+2, Ben Wilson wrote: > > The compiler suggests you re-write it as > > list = [:one] > > list = if false do > [:two | list] > else > list > end > > In your case you have no `else` clause, so if the `if` clause fails, it > returns nil, which sets `list` to nil. > > On Thursday, July 14, 2016 at 10:46:00 AM UTC-4, Fiorillo Nicola wrote: >> >> Sorry about the object: macro have not meaning in this post. >> >> On Thursday, July 14, 2016 at 4:44:36 PM UTC+2, Fiorillo Nicola wrote: >>> >>> Hi all, >>> I have a elixir/phoenix project in production written in 1.2.x elixir >>> version. >>> I'm migrating to 1.3.1 and some "unsafe variable" warning appear: most >>> of them were real and useful but I cannot understand the following >>> situation: >>> >>> #!/usr/bin/env elixir >>> list = [:one] >>> >>> if false do >>> list = [:two | list] >>> end >>> >>> IO.inspect list # warning occurs >>> >>> If, as warning comment suggests, I write >>> >>> #!/usr/bin/env elixir >>> list = [:one] >>> >>> *list =* >>> * if false do* >>> * list = [:two | list]* >>> * end* >>> >>> IO.inspect list >>> >>> # here list is nil >>> >>> list variable assumes an incorrect value. >>> >>> Question is: why elixir compiler assume that block must return a value? >>> >>> Thanks, >>> Nicola >>> >>> >>> -- You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/f96d9c2a-3996-4d45-8512-dcfc232a6be6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
