For anyone else wondering the same, the Elixir docs give more insight into quote/unquote[2]...
...but I'm still unsure as to why the Unicode code uses it. Most of the time it's unquoting byte_size - but why does what looks like a function call need to be unquoted?
It looks like it's defining the same function with different pattern matching clauses using it, e.g.,
for codepoint <- cluster["CR"] ++ cluster["LF"] ++ cluster["Control"] do
def next_grapheme_size(<<unquote(codepoint), rest::binary>>) do
{unquote(byte_size(codepoint)), rest}
end
end
Would define next_grapheme_size with an arg pattern that matches each code point, effectively creating a pattern match switch without boilerplating it? I think? Keen to hear from someone who knows Elixir.But yeah, some more detail on a) what it's doing and b) why it's awesome would've been nice.
[1]: https://github.com/elixir-lang/elixir/blob/0d32ea6bc4bcbd626... [2]: https://elixir-lang.org/getting-started/meta/quote-and-unquo...