Stream: beginners

Topic: Parser example digits


view this post on Zulip Kilian Vounckx (Jul 03 2023 at 10:19):

In the Parser example, there is a function ParserStr.digits. It parses an integer. However, it treats the parsed digits as their unicode codepoint (char 0 is 48 etc). However, because it tries to turn it into a decimal number, the result it wrong (e.g. the string '10' would be interpreted as 10 * 49 + 0 * 48 instead of 10 * 1 + 0 * 0. I think the function should either return the correct decimal number (and maybe be renamed to int?), or it should return a list of digits, so the user can choose what to do with them.

What do you think it should do? I'd be happy to do the fix

view this post on Zulip Anton (Jul 03 2023 at 10:35):

Good catch @Kilian Vounckx! Let's go with returning the correct decimal number and renaming it to positiveInt since -1 is not yet supported. Feel free to ask me for review

view this post on Zulip Kilian Vounckx (Jul 03 2023 at 10:36):

Do I do it in the examples repo, or in the main roc repo? It has the same issue

view this post on Zulip Anton (Jul 03 2023 at 11:25):

Let's fix it in both, the duplication is not ideal but I can't think of a better solution.

view this post on Zulip Kilian Vounckx (Jul 03 2023 at 11:42):

Done in the main repo. It was already duplicate work there, as there is a package example as well as an interface not in a package

view this post on Zulip Kilian Vounckx (Jul 03 2023 at 11:50):

And done in the examples repo

view this post on Zulip Kilian Vounckx (Jul 03 2023 at 11:51):

@Anton The PR's are submitted. I am still running the tests in the main repo. I ran roc check on the files I changed though, so I don't think the tests will fail

view this post on Zulip Anton (Jul 03 2023 at 11:54):

Thanks @Kilian Vounckx I'll check it out in a bit :)


Last updated: Jul 05 2025 at 12:14 UTC