Is there a function like h in iex that returns the string instead of printing to the screen?

It would be useful to somehow have the value that h prints returned so that I can be piped into another function, for example, to search to see if it contains a certain keyword.

You can use Code.fetch_docs. See how h is implemented here : elixir/introspection.ex at 66b4ab19ae0e52ba401b8ba09c5fe9b09947d69e · elixir-lang/elixir · GitHub

7 Likes

Thanks, that’s perfect and a reminder to look into the source code.

2 Likes

Yeah my experience with the Elixir source code is that it is often far more readable than I would have expected. This isn’t always true but it’s true often enough that it’s always worth checking!

4 Likes

What’s the best way find and implementation in the source other than guessing which files look like the right place?

They are linked to from the docs. If you go here IEx.Helpers — IEx v1.16.0 the little icon to the right of the function name is the source code link.

image

3 Likes

you can also literally open a function/module/module.function in your text editor!

iex> open h
iex> open Enum

See IEx.Helpers.open/1 for more information.

3 Likes

This only works if the source file is indeed on the local computer though. It won’t work for precompiled elixir core modules.

3 Likes

I just found that out.

Wow, I don’t know that! Knowing that will aid in my learning a lot. Thanks

1 Like

On my computer I installed Erlang and Elixir with asdf and it does not work with elixir core modules but it works with Erlang ones.

The default installation for elixir on asdf is to just download a precompiled package. Erlang is always built from source.

I remember seeing Erlang being compiled indeed.

By any chance do you know if it possible to install Elixir from source with asdf but keeping a simple vsn in the .tool-versions files (and not a git commit ref). I dont want to force my team to install from source.