Character syntax

Super noob question that I came across while looking at some exercism examples. In charlist like ‘ABCD’ you can’t match on ['A' | tail] like I would have expected. Instead you have to use this question-mark syntax [?A | tail]. Can someone point me to the documentation for that syntax?

1 Like


The ? returns the codepoint for the character.

A charlist is a list of integers, so ABCD is the same as [65, 66, 67, 68].
If you try to match it with ['A' | tail], you’re basically saying the list should look like [[65], 66, 67, 68]. As it’s a list of integers, you need to match the first integer, ie the first codepoint with ?A instead of 'A'.