How do I list all shell variables in IEx?
Asked Answered
D

2

6

I can't figure out how to view my current context in IEx. I want to see a list of all the variable that have been defined in the shell. Is this possible? Thanks.

Divinadivination answered 7/2, 2017 at 1:47 Comment(0)
O
15

You can get the current variables and their values with binding()

e.g.

iex(1)> a = 2
2
iex(2)> b = %{c: 3}
%{c: 3}
iex(3)> binding()
[a: 2, b: %{c: 3}]

See h binding in IEx for more info.

Ope answered 7/2, 2017 at 2:22 Comment(1)
And something like Enum.map(binding(), fn {k, _v} -> k end) or Keyword.keys(binding()) will get you just the variables names (as atoms).Brahui
B
0

Apart from binding/0, you can also use __ENV__.vars.

More info:

Brahui answered 18/10, 2019 at 1:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.