4Clojure banner

4ever-clojure replaces 4Clojure

4Ever-Clojure is a new implementation of 4Clojure.com which has now been decommissioned.

TODO: This section we be updated with details of using 4Ever-Clojure soon.

Coding Challenges: 4Clojure

4Ever-Clojure is an excellent website to help you discover and apply the common functions in the Clojure language.

The website is self-contained so you do not need to install anything, simply paste in the missing code from the tests. One piece of code should solve all the tests for that challenge.

The Problem List shows the challenges categorized by experience level required, (Elementary, Easy, Medium, Hard) to solve them. Start with the easiest problem or work your way through the challenges in any order you wish.

Select the name of a challenge and a new page describes the challenge and presents one or more tests that must pass.

4Ever-Clojure Challenge Example

Enter the code that should be inserted where the __ double underscore characters are.

Press the Run button to see if the code satisfies the tests

A dialog box is displayed showing how many tests have passed and failed

There are over 550 functions in the clojure.core namespace alone, with additional functions in many other namespaces that make up the Clojure Standard Library. It is not required to learn all these functions to be productive in Clojure.

Get help

Look at the Clojure Cheatsheet and Clojure API for an understanding of what functions are available in the core of the Clojure language.

Search directly in ClojureDocs for functions. Each function has a page that describes the function, shows the arguments it takes and provides many examples of its use. At the end of the page are related functions too.

An Internet search of clojure topic, where topic is a name of the thing you want to do, should return many examples of functions that could be useful to solving the challenge. Or

Using let and anonymous functions

The solution submitted should be a single form, which is inserted in the test code where the __ underscore placeholder is. It is therefore not possible to define data with def or a separate function with defn to support the submitted solution.

Use the anonymous function, fn, to define behavior.

(fn [value1 value2]
  (* value1 value2))

Use let to bind a name to a value, so that value can be re-used throughout the expression. let is also useful for breaking the algorithm into smaller pieces, making it easier to solve the challenge.

(let [name value]
  (* 2 value (/ value 4) (+ value 3)))

It is common to combine fn and let to solve the challenges as they grow in complexity

(fn fibonacci [length-of-series]
  (let [fib [1 1]]
    (if (< (count fib) length-of-series)
      "iterate... to implement"

My function is not working

4Clojure uses Clojure 1.5 version and whilst the core of the Clojure language has not altered greatly since 4Clojure was created, there may be a few newer functions that are not supported.

Try the code in a Clojure REPL or create a Clojure project using the latest version of Clojure (1.10.1).


results matching ""

    No results matching ""