This is the original 
thread: 
https://groups.google.com/forum/#!searchin/elixir-lang-core/imperative/elixir-lang-core/3o-omqgCV3E/LQro8PH7EQAJ

You can find another example of discussion 
here: 
https://elixirforum.com/t/fix-scope-warning-without-adding-extra-code/1008/25

These go through the logic, as does the original blog post.

I'm not entirely sure what your macro is trying to do, so it's hard to 
suggest a better pattern. At the moment it looks like it's basically just 
another `if` like construct, which means that it's going to need to abide 
by the same rules.

On Thursday, July 14, 2016 at 4:53:27 PM UTC-4, Fiorillo Nicola wrote:
>
> You're right: it has been covered extensively but, imho, not deeply 
> discussed.
>
> Actually we meet this situation starting from an our macro implementation.
> Here is a POC:
>
> #!/usr/bin/env elixir
> defmodule DoSomethingMacro do
>
>   defmacro __using__(_) do
>     quote do
>       import DoSomethingMacro, only: :macros
>     end
>   end
>
>  defmacro do_something_on_flag(flag, do: block) when is_boolean(flag) do
>     quote do
>       case unquote(flag) do
>         true  -> unquote(block)
>         _     -> IO.puts "do other things"
>       end
>     end
>   end
> end
>
> defmodule DoSomethingMacroTest do
>   use DoSomethingMacro
>
>   def run() do
>     list = [:one]
>     do_something_on_flag(true) do
>       list = [:two | list] # BTW: why not unsafe variable warning?
>     end
>
>     IO.inspect list # unsafe variable warning
>     # list is [:two, :one]
>
>     do_something_on_flag(false) do
>       list = [:three | list] # unsafe variable warning
>     end
>
>     IO.inspect list # unsafe variable warning
>     # list is [:two, :one]
>
>     list =
>     do_something_on_flag(false) do
>       [:fourth | list] # unsafe variable warning
>     end
>
>     IO.inspect list
>     # list is :ok (due to IO.puts "do other things")
>   end
> end
>
> DoSomethingMacroTest.run
>
> In our do_something_on_flag (used as a common library) implementation 
> should not assume that block must return something.
> When we write
>
>     list =
>     do_something_on_flag(false) do
>       [:fourth | list] # unsafe variable warning
>     end
>
> we break the list variable.
> Moreover, if we modify the do_something_on_flag macro in order to manage 
> alse the else clause, we are forced to write something like this
>
>     list =
>     do_something_on_flag(false) do
>       [:fourth | list]
>     else
>         list
>     end
>
> First: this is useless for us because our macro must apply a standard 
> behaviour in an hypothetical else clause and deny the caller to have a 
> different behaviour.
> Second: in my opinion this is an outrage of Elixir elegance and 
> conciseness.
>
> On Thursday, July 14, 2016 at 6:03:04 PM UTC+2, Ben Wilson wrote:
>>
>> This has been covered extensively in a number of places, the most 
>> definitive being here: 
>> https://github.com/elixir-lang/elixir/blob/v1.3/CHANGELOG.md
>>
>>> ...
>>>>>>
>>>>>

-- 
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/fd3f9313-dd1c-4555-ae65-d67bcf752aa6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to