December 2015
Intermediate to advanced
400 pages
13h 3m
English
The error messages printed out by evaluate(_:) are useful, but not as useful as they could be. Here are a couple of erroneous inputs and the error messages they produce:
evaluate("1 + 3 + 7a + 8")
> Input contained an invalid character: a
evaluate("10 + 3 3 + 7")
> Invalid token during parsing: .Number(3)
Make these messages more helpful by including the character position where the error occurred. After completing this challenge, you should see error messages like this:
evaluate("1 + 3 + 7a + 8")
> Input contained an invalid character at index 9: a
evaluate("10 + 3 3 + 7")
> Invalid token during parsing at index 7: 3
Hint: Printing a String.CharacterView.Index will show the character position corresponding ...
Read now
Unlock full access