is there a way to suppress warnings like `variable x is unused` ?

1,448 views
Skip to first unread message

atkaaz

unread,
Jul 24, 2013, 8:57:47 AM7/24/13
to elixir group
like if I define a variable and I used it only inside Code.eval_string, but I don't want to define it inside Code.eval_string as a workaround(didn't even try)

but suppress the warning only on the specific line, not globally

Eric Merritt

unread,
Jul 24, 2013, 9:05:27 AM7/24/13
to elixir-l...@googlegroups.com
Well you can always add a leading underscore to the variable, that
basically tells the compiler that you know its unused and thats ok. So
variable `x` becomes `_x`.
> --
> 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 elixir-lang-ta...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Eric Meadows-Jönsson

unread,
Jul 24, 2013, 9:07:26 AM7/24/13
to elixir-l...@googlegroups.com
You cannot use external defined variables inside Code.eval_string you have to pass them via the binding parameter.

--
Eric Meadows-Jönsson

atkaaz

unread,
Jul 24, 2013, 9:10:26 AM7/24/13
to elixir group
I just noticed that while purposefully forgetting to rename the var inside the eval... the test still worked cause it had the same effect so I couldn't tell the external vars weren't seen inside eval.

atkaaz

unread,
Jul 24, 2013, 9:22:12 AM7/24/13
to elixir group
That's pretty cool actually, I wonder if it's a side effect of when just _ is used, or if it's purposefully so

Eric Merritt

unread,
Jul 24, 2013, 3:00:21 PM7/24/13
to elixir-l...@googlegroups.com
Its kind of a side effect, but a purposeful side effect. That is
everything that starts with '_' is a throw away, including '_'. Thats
actually pretty common in functional languages.

atkaaz

unread,
Jul 24, 2013, 3:01:27 PM7/24/13
to elixir group
I kinda wish it worked for functions too (if it does, maybe I did it wrong?)

Eric Merritt

unread,
Jul 24, 2013, 3:04:18 PM7/24/13
to elixir-l...@googlegroups.com
no, it doesn't work for functions :) basically you can just export
them (def instead of defp) if you want the warning to go away. Thats
good for testing. However, if your code is 'done' and you still have
functions that are private and unused you should probably reconsider
what you are doing.
Reply all
Reply to author
Forward
0 new messages