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
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
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
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43757 214
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement