Exercises for learnraku.dev. Each exercise is a small Raku task with a Behave spec that defines when it is solved. The site consumes this repository as a git submodule.
exercises/<category>/<exercise>/
README.md the prompt shown to the learner
Exercise.rakumod the starting code (a stub the learner completes)
spec.raku the behave spec that decides pass or fail
solutions/<category>/<exercise>/
Exercise.rakumod a working solution that passes spec.raku
The two directories mirror each other. Every exercise under exercises/ has a
matching solution at the same path under solutions/. The site only ships
exercises/ into the sandbox, so we keep the answer in solutions/ and never
inside the exercise's own Exercise.rakumod.
Directories are numbered in tens (0010-, 0020-, ...) so new items can be
inserted without renumbering.
You need Rakudo (raku) and zef, then you can install Behave:
zef install BDD::Behave
This installs the behave command used to run specs.
A spec.raku does use Exercise;, so behave finds Exercise.rakumod
through RAKULIB. Run these from the repository root.
Against the starting stub, which must fail (an unsolved exercise):
RAKULIB=exercises/0010-scalars/0010-greeting \
behave exercises/0010-scalars/0010-greeting/spec.raku
Against the solution, which must pass:
RAKULIB=solutions/0010-scalars/0010-greeting \
behave exercises/0010-scalars/0010-greeting/spec.raku
bin/check runs the quality checks the site depends on. Run it from the
repository root.
raku bin/check # every exercise
raku bin/check 0010-scalars/0010-greeting # one exercise
For each exercise it confirms:
README.md,Exercise.rakumod, andspec.rakuexist underexercises/.- A matching
Exercise.rakumodexists undersolutions/. - The starting
Exercise.rakumoddoes not already passspec.raku. A stub that passes means the exercise gives the answer away. - The solution does pass
spec.raku.
It exits non-zero if anything fails. A pull request must have raku bin/check
passing for the exercises it touches.
- Pick or create a category directory, then add
<NNNN>-<name>/inside it. - Write
README.mdwith the prompt. - Write
Exercise.rakumodas a stub the learner completes. It must not pass the spec on its own. - Write
spec.rakuusing behave, covering the behavior you want. - Add
solutions/<category>/<exercise>/Exercise.rakumodthat passes the spec. - Run
raku bin/check <category>/<exercise>until it is green.