robertluo / rich4clojure

Rich 4Clojure – A Rich Comments version of 4Clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rich 4Clojure

Welcome to the Rich Comment Form (RCF) copy of 4Clojure! ❤️

What it is

  1. A repository that lets you learn and practice Clojure, directly from the comfort of Clojure REPL enhanced editor.
  2. A ”copy” of the now closed 4clojure.com site. It served us so wonderfully well!

Anyway, if you have come here to practice Clojure, you are at the right place!

How it works

First thing first. If you are totally unfamiliar with Clojure, this might be better used as your second step in Getting Started. A super quick first step might be to use Calva's Getting Started REPL. You'll need to at least know how to:

  • Start a project REPL (starting this project's REPL, that is. Which is very easy if you are using Calva)
  • Load a Clojure file
  • Evaluate forms

Get started

To get to where you can start solving problems:

  1. Fork and clone. I suggest you also make a branch for your practicing. This because you will be modifying the files, and might still want to be able to push clean pull requests.
  2. Open the project in your Clojure-enabled editor.
  3. Start the Rich 4Clojure project REPL and connect it to your editor session. If you are using Calva, this is as easy as issuing the Start a Project REPL (aks Jack-in) command and select Rich 4Clojure in the Project types menu that pops up.
  4. Load the file dev/repl.cljc.
    • This will enable the test runner to run the problem tests that you find in each problem file.

Find problems

The problems are contained in subfolders of the general difficulty level:

  1. src/rich4clojure/elementary
  2. src/rich4clojure/easy
  3. src/rich4clojure/medium
  4. src/rich4clojure/hard

Find suitable/fun problems and hack away. 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.

Solve problems

Each problem has at least:

  1. A title
  2. A description
  3. A definition of the symbol __
    (def __ :tests-will-fail)
    • This symbol is used by the tests.
  4. An ”open” (comment ...) form (a Rich Comment Form, RFC)
  5. A (tests ...) form

Some problems also have restrictions, e.g:

(def restricted [map mapcat])

Restrictions list ”things” shipped with Clojure that your solutions are 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.

Running the tests

The process of taking on a problem is:

  1. Open the file
  2. 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]
    
    ...
    
  3. 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:

  1. Start with moving the (def __ :tests-will-fail) form inside the (comment ...) form.
  2. Redefine __ to a function make the tests pass, e.g.
    (defn __ [x y z] ...)

For some problems you rather need to edit the tests and replace each instance of __ with different (or the same) answers.

Basically, treat both the (comment ...) and the (tests ...) forms as your RFCs. Fiddle, evaluate, fiddle, evaluate. Until you have found the solution.

Solved it?

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!

Stuck?

The #4clojure, #beginners and #clojure channels at the Clojurian's Slack might be places to ask for hints. You might try the Discussions feature. 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.

What about the name?

The name, Rich 4Clojure, comes from the fact that it relies on Rich Comments and also uses a test utillity called RCF which is building on the same philosophy. (Also reading it like ”rich forclosure” builds on the joke that the original site was pulling. 😄)

Work in progress

This is the first version from a quite automated translation of the orginal problems. There'll be dragons. Please consider filing issues, starting discussions, or chat me up on the Clojurian's Slack (I'm @pez, there).

PR:s are also welcome. If it is the content of a particular problem you want to suggest changes for, edit the problems.edn file.

Support the project

Please consider contributing. Issues and pull requests are welcome. Though I have to figure out a good process for Prs. It is quite a mess in my translation script right now. So I might not always be super quick to pull

The Discussions tab is also there for us to discuss both the project and solutions.

If you want to contrubute with problems, that is also super welcome. I suggest you start that with adding it as a suggestion in Discussions. Then, if we agree the problem should be added, add it as a PR to the problems.edn file, and I will generate the files and gists from it. (Until I've set up a CI/CD pipeline for this.)

If you want to encourage my work with this project you are welcome to sponsor me:

See also

  • 4ever-clojure – A web based ”always up” copy of the original 4Clojure. It has listings of all working solutions that that were submitted to the original site.

About

Rich 4Clojure – A Rich Comments version of 4Clojure

License:Eclipse Public License 1.0


Languages

Language:Clojure 100.0%