What is this construct?

I found this code in Logger.Formatter. I’ve never seen it before and can’t find it documented. It seems to create an integer literal. Can someone explain ?= and ?\s?

  defp output(:metadata, _, _, _, meta) do
    Enum.map(meta, fn {key, val} ->
      [to_string(key), ?=, metadata(val), ?\s]
    end)
  end
1 Like

That’s used to get the character’s codepoint. So ?a == 97

It’s referenced part-way down this page:

4 Likes

Just to drive that information to completion relative to the original post.

?= is the code point for the “=” character so ?= evaluates to 61
?\s is the code point for a space character so ?\s evaluates to 32

It may also be worth mentioning that what Logger is doing here is building an “IO list” or IO Data. See, for example:

and

https://www.bignerdranch.com/blog/elixir-and-io-lists-part-1-building-output-efficiently/

5 Likes