Repository navigation
Conversation
Adds the bank-account practice exercise (difficulty 5), split out of exercism#307. An account is opened before use and closed when it is not needed any more, and every operation on a closed account is an error. Three adjustments so the exercise builds on the V 0.4.8 that the current test runner image pins as well as on current V: - The mutex field is called `mutex` and is taken with `@lock()`. `lock` is a reserved keyword in V 0.4.8, so neither the field name nor the method call parses there, while `@lock()` is the name V gives the method on every version the track supports. - `balance` takes its receiver by value instead of by reference, so that the mut method behind the mutex can be called at all: V 0.4.8 demands a `mut` receiver variable and rejects `mut` on a reference receiver, and the mutex is a shared pointer either way. - run_test.v waits for its 1000 workers on a buffered channel rather than on a `sync.WaitGroup`. V 0.4.8 rejects calling `add`/`done` on a non-`mut` waitgroup, but a `mut` one shared with spawned functions miscompiles on V 0.5.2 and crashes in `_InterlockedExchangeAdd64`, so neither form of the waitgroup works on both. A channel does. The methods return `!` rather than `!void`, because V 0.4.8 rejects `!void` and asks for `?` instead. Registers the exercise in config.json. Verified with bin/verify-exercises-in-docker (the current test runner image) and with V 0.5.2 for bin/test. configlet lint passes, and v fmt -l / v vet are clean on the new files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the Bank Account practice exercise (difficulty 5), split out of #307.
bank-account.v-- stub.meta/example.v-- example solutionrun_test.v-- 17 tests, built from the canonical data inproblem-specifications.meta/config.json,.meta/tests.toml,.docs/config.json-- registers the exerciseAdjustments for the test runner's V version
Three adjustments so the exercise builds on the V 0.4.8 that the current test
runner image pins as well as on current V:
mutexand is taken with@lock().lockis areserved keyword in V 0.4.8, so neither the field name nor the method call
parses there, while
@lock()is the name V gives the method on everyversion the track supports.
balancetakes its receiver by value rather than by reference, so the mutmethod behind the mutex can be called at all: V 0.4.8 wants a
mutreceivervariable and rejects
muton a reference receiver. The mutex is a sharedpointer either way, so the account is still guarded.
run_test.vwaits for its 1000 workers on a buffered channel rather than ona
sync.WaitGroup. V 0.4.8 rejects callingadd/doneon a non-mutwaitgroup, but a
mutone shared with spawned functions miscompiles onV 0.5.2 and crashes in
_InterlockedExchangeAdd64, so no form of thewaitgroup works on both. A channel does.
!rather than!void, because V 0.4.8 rejects!void.The stub carries the same adjustments, so a student on V 0.4.8 starts from
something that parses.
One self-contained commit that touches nothing outside the exercise, so it can be merged on its own.
Verification
bin/verify-exercises-in-docker(the currentvlang-test-runnerimage, V 0.4.8): pass, 17/17 tests.vlang/setup-vinstalls forbin/testin CI: pass.configlet lintpasses;v fmt -landv vetare clean on the new files.For the merge commit
Not needed: a brand new exercise does not change the outcome of any existing exercise's tests.