Migrate to new roc#198
Conversation
…xercises/practice
|
This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested. If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos. For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping |
| app [main!] { | ||
| pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.7/DuRUyJh31Gt41YArMcVcvybLa2bCWboccWQ7Zq1KZPZ6.tar.zst" |
There was a problem hiding this comment.
roc-platform-template-zig 0.8 is already out, it is possible that you need 0.9 (not out yet) with the latest Roc nightly due to https://roc.zulipchat.com/#narrow/channel/397893-announcements/topic/nominal.20field.20ordering.20is.20now.20preserved/near/605353849
| ?? "" | ||
| } | ||
|
|
||
| # List.reverse should soon be available in Roc's builtins |
There was a problem hiding this comment.
List.rev is available now.
| result = solve("I + BB == ILL") | ||
| Set.from_list(result ?? []) == Set.from_list( |
There was a problem hiding this comment.
We typically like to steer people away from using ?? for default value fallbacks because they fail silently.
I just tried changing it to:
result = solve("I + BB == ILL")?
And that works in both cases Err or Ok.
There was a problem hiding this comment.
Here the silent failure is not a problem of course but we want to make sure people don't see this as the way to handle errors in Roc.
| app [main!] { | ||
| pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.20.0/X73hGh05nNTkDHU06FHC0YfFaQB1pimX7gncRcao5mU.tar.br", | ||
| unicode: "https://github.com/roc-lang/unicode/releases/download/0.3.0/9KKFsA4CdOz0JIOL7iBSI_2jGIXQ6TsFBXgd086idpY.tar.br", | ||
| pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.7/DuRUyJh31Gt41YArMcVcvybLa2bCWboccWQ7Zq1KZPZ6.tar.zst", |
There was a problem hiding this comment.
This one should be updated to latest release as well.
| result = [1, 3, 4, 6, 8, 9, 11] |> find(6) | ||
| result == Ok(3) | ||
| expect { | ||
| result = [1, 3, 4, 6, 8, 9, 11]->find(6) |
There was a problem hiding this comment.
We typically write this as result = find([1, 3, 4, 6, 8, 9, 11], 6), that looks more familiar to most people.
| rolls.fold_until( | ||
| Ok(new_game), | ||
| |state, pins| { | ||
| match state { | ||
| Ok(game) => { | ||
| match game.roll(pins) { | ||
| Ok(updated_game) => Continue(Ok(updated_game)) | ||
| Err(err) => Break(Err(err)) | ||
| } | ||
| } | ||
| Err(_) => { | ||
| crash "Impossible, we don't start or continue with an Err" | ||
| } | ||
| } | ||
| }, | ||
| ) |
There was a problem hiding this comment.
Turning this into a for loop would probably make it easier to understand.
| result == Ok([1]) | ||
| expect { | ||
| coins = [1, 5, 10, 25] | ||
| result = coins->find_fewest_coins(1) |
There was a problem hiding this comment.
Same as before, it should preferably be find_fewest_coins(coins, 1)
| expect { | ||
| _result = CircularBuffer.create({ capacity: 1 }) | ||
| .write( | ||
| 1, | ||
| )? | ||
| .read()? | ||
| ->expect_value(1) | ||
|
|
||
| Bool.True | ||
| } |
There was a problem hiding this comment.
This looks unconventional, I personally would prefer more duplication that is easier to understand.
| app [main!] { | ||
| pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.20.0/X73hGh05nNTkDHU06FHC0YfFaQB1pimX7gncRcao5mU.tar.br", | ||
| isodate: "https://github.com/imclerran/roc-isodate/releases/download/v0.6.2/73w_H-aSJNcWqtXvMG4JQw_HoaApMBLnE92XD4OcVGU.tar.br", | ||
| pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/0.7/DuRUyJh31Gt41YArMcVcvybLa2bCWboccWQ7Zq1KZPZ6.tar.zst", |
There was a problem hiding this comment.
Another one to update to the latest version.
This PR migrates the Roc track to the new zig-based Roc compiler and its new syntax.
At the time of writing: