Skip to content

feat: add bank-account exercise - #319

Closed
metif12 wants to merge 1 commit into
exercism:mainfrom
metif12:add/bank-account
Closed

metif12 wants to merge 1 commit into
exercism:mainfrom
metif12:add/bank-account

Conversation

@metif12

@metif12 metif12 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

What

Adds the Bank Account practice exercise (difficulty 5), split out of #307.

  • bank-account.v -- stub
  • .meta/example.v -- example solution
  • run_test.v -- 17 tests, built from the canonical data in problem-specifications
  • .meta/config.json, .meta/tests.toml, .docs/
  • config.json -- registers the exercise

Adjustments 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:

  • 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 rather than by reference, so the mut
    method behind the mutex can be called at all: V 0.4.8 wants a mut receiver
    variable and rejects mut on a reference receiver. The mutex is a shared
    pointer either way, so the account is still guarded.
  • 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 no form of the
    waitgroup works on both. A channel does.
  • The methods return ! 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 current vlang-test-runner image, V 0.4.8): pass, 17/17 tests.
  • V 0.5.2, the version vlang/setup-v installs for bin/test in CI: pass.
  • configlet lint passes; v fmt -l and v vet are 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant