The Read-Evaluate-Print Loop

Web Development with Clojure, Third Edition — by Dmitri Sotnikov, Scot Brown (81 / 107)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Writing Code That Writes Cod e for You | TOC | Calling Out to Java 👉

Another big aspect of working in Clojure is the read-evaluate-print loop (REPL). In many languages you write the code, and then you run the entire program to see what it does. In Clojure, most development is done interactively using the REPL. In this mode we can see each piece of code we write in action as soon as it’s written.

In nontrivial applications, it’s often necessary to build up a particular state before you can add more functionality. For example, a user has to log in and query some data from the database, and then you need to write functions to format and display this data. With a REPL you can get the application to the state where the data is loaded and then write the display logic interactively without having to reload the application and build up the state every time you make a change.

This method of development is particularly satisfying because you see immediate feedback when making changes. You can easily try things out and see what approach works best for the problem you’re trying to solve. This encourages experimentation and refactoring of the code as you go, which in turn helps you to write better and cleaner code.

👈 Writing Code That Writes Cod e for You | TOC | Calling Out to Java 👉

Web Development with Clojure, Third Edition by Dmitri Sotnikov, Scot Brown can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.