vonH

vonH

Is there an elixir function that prints out the type of a value and display its fields?

Is there an elixir function to tells the type of a value and display its fields(if it has any)?

For instance I am leaning Plug and want to know what type conn is and display its fields.

One more thing does Elixir have structs or objects as they are understood in languages like C or Pascal?

Most Liked

chrismccord

chrismccord

Creator of Phoenix

See the the i/1 helper docs in IEx:

Prints information about the data type of any given term.

## Examples

    iex> i(1..5)

Will print:

    Term
      1..5
    Data type
      Range
    Description
      This is a struct. Structs are maps with a __struct__ key.
    Reference modules
      Range, Map

Example:

iex(19)> i File.stat!("README.md")
Term
  %File.Stat{access: :read_write, atime: {{2017, 3, 31}, {21, 24, 2}}, ctime: {{2017, 3, 31}, {18, 56, 52}}, gid: 20, inode: 10353339, links: 1, major_device: 16777220, minor_device: 0, mode: 33188, mtime: {{2017, 3, 31}, {18, 56, 52}}, size: 2879, type: :regular, uid: 501}
Data type
  File.Stat
Description
  This is a struct. Structs are maps with a __struct__ key.
Reference modules
  File.Stat, Map
Implemented protocols
  IEx.Info, Inspect
11
Post #3
OvermindDL1

OvermindDL1

inspect(blahSomething) returns a string representation of whatever blahSomething is.

IO.inspect(blahSomething) prints the string representation of whatever blahSomething is to the standard output.

All of this is documented in the manual too. :slight_smile:

Elixir’s structs are like structs in pascal or c yes, underneath they are just statically keyed maps, they are not packed in memory as in pascal or c though, especially since memory is not really a concept on the EVM, it manages it for you.

There is no static typing, however the dialyzer tool (also detailed in the manual) is an awesome tool that runs over your code and checks the success typing of your program, Dialyxer is a dead-simple Elixir interface for using it and I highly recommend it. :slight_smile:

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement