This project contains a set of JVM implementations of a reverse-polish style calculator. They are written to be used as supporting materials for a set of blog postings on the KSM Partners Blog:
- Part 0: Introduction
- Part 1: A Simple RPN Calcualtor in Java and the Command Pattern
- Part 2: Composite Commands
- Part 3: Implementing Undo
- Part 4: A Noun for State
- Part 5: Eliminating the Globals
- Part 6: Refactoring the REPL
- Part 7: Refactoring Loops with Reduce
Because of the intent for this code to support a series of blog posts, the code is focused more on concision and readability than on robustness.
There are two top level sub-projects at the root of the distribution:
java project contains the
Java implementations of the calculator and is
built with Maven. The
contains the Clojure implementations, and is
built with Leiningen.
For both sub-projects, there is a top-level shell script,
that will build and then execute the project.
basic- A simple RPN calculator with support for the four basic mathematical operations and not much else.
basicextended with composite commands that can be composed of a sequence of other commands.
compositeextended with the ability to reverse the effects of a command that's already been executed.
undoable, with all calculator state moved into a first-class object.
stateobjectwithout global variable.
functionalrf- A minor refactoring of
functionalthat simplifies command state management.
reducer- A version of
functionalrfthat uses functional reduction to replace explicit looping.
functionalrf- A reimplementation of the Java
functionalrfbuild in Clojure.
functionalrfextended with a macro to automate generation of stack transformation commands.
dfcompile- A version of
macrothat adds a simple compiler that translates from sequences of calculator operators into Clojure function definitions.
License and copyright
Copyright (c) KSM Technology Partners. All rights reserved.
The use and distribution terms for this software are covered by the Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can be found in the file epl-v10.html at the root of this distribution. By using this software in any fashion, you are agreeing to be bound by the terms of this license. You must not remove this notice, or any other, from this software.