Below you will find pages that utilize the taxonomy term “Clojure”
Posts
Migrating to Docker
I’ve been running a couple of servers on DigitalOcean for some time. I wanted to consolidate the services on each of these servers into one host, but in separate virtual environments, so this seemed like a good opportunity to try out Docker. Docker is a technology allowing us to create processes running within a Container - a sort of lightweight virtual machine that shares system resources with the host such as processes, RAM, and hard disk space.
Posts
Guess the Number, Part 5 - letting the player guess with cond and keywords
In this final part, we’ll finish the game by adding a second game mode which lets the player guess a number that the computer has thought of. We’ll also allow the player to choose between the two game modes. Along the way, we’ll do some reorganising of our code and learn a few new forms.
Code cleanup So far, we’ve done all our work in the -main function of core.
Posts
Guess the Number, Part 4 - looping
Currently, our Guess the Numbers game only works for 1 round: the computer makes a guess, the player answers, and the game ends. In this tutorial, we’ll keep the game going until the answer is reached, which we can accomplish using a loop.
Basically, we would like to accomplish this repetitive behavior:
I've thought of a number between 0 to 99... can you guess it? > 45 Bigger! > 78 Smaller!
Posts
Guess the Number, Part 3 - conditionals
In this part, we’ll have the computer react accordingly to the player input.
Conditional statements: if In programming, we use conditional statements to decide how the program will proceed when given a certain condition. Clojure supports conditional branching via a number of forms: if, while, cond, condp, and so on. The most basic of the forms is if.
(if (= 5 (+ 2 3)) "5 is equals to 2 plus 3" "5 is not equal to 2 plus 3") Try the above snippet in the REPL to see how if works.
Posts
Guess the Number, Part 2 - Computer's first guess, the REPL, and let
In this tutorial, we will get our feet wet with the Read-Eval-Print-Loop (or REPL for short) while creating the first part of our game, which is to let the computer guess the number that the player is thinking of.
The Logic To play the game, the computer has to guess a number between 0 to 99. One approach could be for the computer to keep on picking a random number until it gets the answer, but we would like for it to always get the right answer eventually.
Posts
Guess the Number, Part 1 - Hello, World!
Guess the Number is a very simple game where you try to guess the number that the opponent is thinking of. The opponent will then tell you whether your guess was bigger or smaller than the actual answer.
In this project, we will create a Guess the Number game where both you and the computer can take turns coming up with the number. Here’s what the game will look like after it’s done:
Posts
Getting Set Up with Clojure
Before you begin writing Clojure, you’ll need to equip yourself with some tools first.
Installing Java Clojure runs on top of the Java Virtual Machine (JVM). The JVM can be obtained by installing the Java Runtime Environment (JRE) or the Java Development Kit (JDK). Strictly speaking, you can run and do development with Clojure using the JRE alone, but it’s a good idea to install the JDK as it’s needed by leiningen (see below).