The Ecto source code makes use of expressions ?0
, ?1
, etc. You can see how they evaluate:
iex(14)> ?0
48
iex(15)> ?1
49
iex(16)> ?2
50
What does that mean though? This is very hard to search for. What does the ?<character>
actually do?
The Ecto source code makes use of expressions ?0
, ?1
, etc. You can see how they evaluate:
iex(14)> ?0
48
iex(15)> ?1
49
iex(16)> ?2
50
What does that mean though? This is very hard to search for. What does the ?<character>
actually do?
Copyright © 2021 Jogjafile Inc.
From: https://elixir-lang.org/getting-started/binaries-strings-and-char-lists.html#unicode-and-code-points
If you aren't familiar with code points:
The
?<character>
can also be used in interesting ways for pattern matching and guard clauses.The Elixir docs on it also clarify that it is only syntax. As @sabiwara points out:
As @Everett noted in the comments, there is a helpful package called
Xray
that provides some handy utility functions to help understand what's happening.For example
Xray.codepoint(some_char)
can do what?<char>
does but it works for variables whereas?
only works with literals.Xray.codepoints(some_string)
will do the whole string.