What is #ecto.changeset<action: ...> syntax?

I am reading this guide:

https://hexdocs.pm/ecto/getting-started.html

In the line:

When this third line runs, we’ll see this:

{:error,
 #Ecto.Changeset<action: :insert, changes: %{},
  errors: [first_name: "can't be blank", last_name: "can't be blank"],
  data: #Friends.Person<>, valid?: false>}

What is the syntax #Ecto.Changeset<action: ...> ?

In Elixir pound signs start a comment, so it seems this is part of the Ecto DSL? Where can I read a reference?

When I google “Ecto DSL syntax” I get this page which does not have any pound signs (#) that are not comments and does not have any <>'s like what I just quoted.

So I am having trouble understanding where the reference is for this syntax. What language is the code snippet written in, which includes a # sign and <> brackets?

Elixir uses the Inspect protocol wherever data is inspected.

The notation of #StructName<…> is a convention for structs to hide certain internals, while showing others. The leading # indeed makes this a comment, because the inspected format is not valid elixir and therefore cannot be used to get back the datastructure, which was initially inspected.

Where possible the convention has been superseeded with a newer convention of letting the inspected value be valid code to construct the inspected value without showing the internals. E.g. Decimal values inspect as e.g. Decimal.new("1.00"). That’s not possible with changeset though, as their internals cannot be easily constructed.

4 Likes

Thank you! For me when I inspect a struct I get the format %User{age: 27, name: “John”} so I misinterpreted the line.

You can always inspect the real data structure by passing structs: false option to IO.inspect.