You will be solving problems one at a time, each in a separate problem_###.clj
file.
First you need to start the project and connect the editor to its REPL. This is how you do it using Calva:
-
Click the REPL button in the status bar
Don't see the REPL button?
This could be because some firewall or adblocker prevents the downloading of the Calva extension. See issue #9 for more clues on this.
-
Select Start your project with a REPL server and connect (aka Jack-in) from the quick pick menu
-
Select Rich 4Clojure in the Project types menu.
The REPL button will turn Calva-yellow when the REPL is connected. Now Calva is ready to be used for solving problems! See below.
Or, maybe you don't feel ready just yet?
I am new to Calva
To learn the basics of using the Clojure REPL with Calva, use the REPL button and select Fire up the ”Getting Started” REPL.
(If you are already connected, you'll first need to select Disconnect from the REPL server. Then click the button again.)
See calva.io/getting-started for what to expect.
I am new to Clojure
Welcome to Clojure! ❤️
There is a lot to learn and many concepts to grasp. But fear not!
- With the Gitpod option provided with this repository, you don't need to install anything and can wait with having to understand all the things about how Clojure is wired up and such.
- The Getting Started REPL (see I am new to Calva) also sports a basic Clojure guide.
- The problems in this repository starts of from really easy and are designed to build up your Clojure skills.
The problems reside, each in separate .clj
files, in subfolders of the general difficulty level:
src/rich4clojure/elementary
src/rich4clojure/easy
src/rich4clojure/medium
src/rich4clojure/hard
Find suitable/fun problems and hack away on it. Right now the original site's guidance on which order to take on the problems are not translated to this repo, but generally just in numerical order at the difficulty level of your choice should work.
Each problem has at least:
- A title
- A description
- A definition of the symbol
__
(def __ :tests-will-fail)
- The tests reference this symbol. You are sometimes supposed to redefine it to something that makes the tests pass, and sometimes you will need to edit the
(tests ...)
form and replace this symbol with something else.
- The tests reference this symbol. You are sometimes supposed to redefine it to something that makes the tests pass, and sometimes you will need to edit the
- An ”open”
(comment ...)
form (a Rich Comment Form, RFC) - A
(tests ...)
form
Some problems also have restrictions, e.g:
(def restricted [map mapcat])
Restrictions list ”things” shipped with Clojure that your solution is not allowed to use. Your editor's lookup features can give you documentation and defintions for the restricted symbols. Sometimes using the restricted ”things” in your solution, or just peeking at their documentation can help you find solutions that don't use them.
The process of taking on a problem is:
- Open the file
- Load the file
- This will run the tests and they will fail. A failing test looks something like so:
clj:rich4clojure.easy.problem-39=> ; Evaluating file: problem_39.clj ❌ rich4clojure.easy.problem-39:21 in (__ [30 20] [25 15]) [25 15] :≠ [30 25 20 15] ...
- Make the tests pass.
- A successful test run looks something like so:
clj:rich4clojure.easy.problem-39=> ; Evaluating file: problem_39.clj ✅✅✅✅
To rerun the tests, either reload the file or evaluate the (tests ...)
form. This depends a bit on the problem and on your workflow. Here's a suggestion for problems which wants you to define a function:
- Start with moving the
(def __ :tests-will-fail)
form inside the(comment ...)
form - Redefine
__
to a function that will make the tests pass(defn __ [x y z] ...)
NB: For some problems you rather need to edit the tests and replace each instance of __
with your answer.
Basically, treat both the (comment ...)
and the (tests ...)
forms as your RCFs. Think, fiddle, evaluate, think, fiddle, evaluate, ... until you have found the solution.
Each problem has a gist linked at the bottom. Please consider sharing your solution as a comment on the gist. Other Clojurians will benefit from seeing how you solved it.
Also: 🍰 Congratulations! 🎉 Now take on the next problem!
The #4clojure
, #beginners
and #clojure
channels at the Clojurian's Slack might be places to ask for help. You can also try the Discussions tab in this repo. Also: Each problem has a gist linked at the bottom. The gist's comment section might contain solutions from other users. Sometimes a peek is enough to give some guidance. But, yeah, major spoiler alert.