Kalkulon
Jürgen Holetzeck's programmable expression calculator for programmers - C operators and casts, hex and binary literals, lists and Mathematica-style pure functions, with its own small scripting language - freeware for Windows from around 2003, GPL-licensed Qt and Android versions until 2013
Created by Jürgen Holetzeck
Kalkulon is a programmable calculator for programmers, written by the German developer Jürgen Holetzeck and maintained by him from around 2003 until 2013. On the surface it is a desktop calculator: type (0x10>>3)+(6|4)*7 and it answers. Underneath is a small interpreted language. It has C’s full operator set and integer casts, hex and binary literals, strings, nested lists, user-defined functions, if/while/do/for control structures and anonymous “pure functions”. Programs live in .k script files that the calculator loads and runs. It began as Windows freeware and became GPL-licensed open source in 2007, with Qt builds for Windows and Linux and, at the end, an Android app.
Kalkulon is a small project, but it is a good example of a whole genre: the programmer’s calculator that grows until it becomes a programming language.
A Note on the Catalogue Record
The CodeArchaeology encyclopedia lists Kalkulon as a 1988 procedural spreadsheet language, historical, with commercial use into the 1990s. Most of that could not be confirmed. The only software called Kalkulon that left any public trace is Holetzeck’s calculator. It is not a spreadsheet, it was never sold, and its own documentation dates it to 2003. No 1988 spreadsheet of that name turned up in web searches, Wikipedia (in nine languages), Wikidata, FOLDOC, the HOPL encyclopedia, the Esolang wiki, Rosetta Code, PLDB or the Internet Archive’s full-text search. The one other “Kalkulon” that keeps appearing is the Czech and Polish name for Calculon, the robot soap-opera actor in Futurama.
This page therefore describes the calculator. It uses 2003 as the year because that is the first year in every one of Holetzeck’s copyright notices. No release from that year has survived, though. The earliest version that can actually be dated is 2.7.5.0, released on 3 October 2006. Its version number, and a change log that reaches back through 2.7.3.1, suggest that earlier releases existed, but none of them has been found.
History & Origins
Kalkulon’s early history is known only from its author’s pages. Those pages were captured by the Internet Archive from December 2006 onwards, first on Holetzeck’s personal space at the German ISP Arcor and later at holetzeck.de/kalkulon and kalkulon.de.
Holetzeck described the program the same way throughout its life: “a programmable expression calculator for programmers”. The 2006 feature list reads like a working programmer’s list of complaints about the Windows calculator:
- C-like syntax for expressions, e.g.
(0x10>>3)+(6|4)*7 - variables, e.g.
bitmask = 0x0F0F; 0x1234&bitmask - user-defined formulas and programs, e.g.
AddMul(a,b,c)=(a+b)*c; AddMul(1,2,3) - full programmability with
if,while,doand so on - a result history (
out,outl) - casts, e.g.
((u8)-1)<<8 - decimal, hex and binary formats, e.g.
(128+0x3d)&0b01101100 - strings and lists
- configurable syntax colouring “for easy use of long expressions”
- an
autoload.kfile for the user’s own variables, formulas and programs - user-defined functions supplied through a DLL
- scripting through a console version,
kkc.exe
The language is a by-product of that list. Once a calculator lets you define functions and loop, people start writing programs in it. The example scripts later published on the Kalkulon site (as archived in 2016) include big-integer and big-number arithmetic, complex numbers, CRC and checksum calculation, Base64, matrices, primes, an IP-address calculator and a crossword helper.
In 2006 the program was freeware for Windows 9x/ME, 2000/NT and XP, with a graphical front end based on Microsoft’s MFC. The interpreter core was already separate from the GUI. Holetzeck published the source of the console version, noted that it was “solely written in ISO-C++”, and invited anyone who wanted to port it to another operating system to contact him. It compiled with Visual C++ 6, Visual C++ 2005 (native and /clr:pure), MinGW and gcc on Linux.
Evolution
| Version | Date | What changed |
|---|---|---|
| 2.7.4.0 | before Oct 2006 | readline support for Linux builds of the console version |
| 2.7.5.0 | 3 Oct 2006 | escape sequences \\, \", \n, \t in strings; printf-style %b binary formatting fixes |
| 3.0.0.0 | 26 May 2007 | new Qt GUI for Windows and Linux; complete source released as free software |
| 3.0.0.1 | 10 Nov 2007 | GUI fixes (help file path, options dialog); Windows binaries now built with Qt 4.3.2, according to the readme |
| 3.0.0.2 | 7 Feb 2008 | SetRecursionLimit() (default 150) so runaway recursion no longer overflows the stack; licence stated as GNU GPL |
| 3.0.1.0 | 26 Apr 2008 | matching parentheses and brackets highlighted while editing |
| 3.0.1.4 | 22 Jan 2011 | locale fix needed under newer Qt; Mercurial repository on Bitbucket by mid-2011 |
| 3.0.2.0 – 3.0.3.0 | 2011–2013 | core ported to ARM/Android; GetTicks() on glibc; Exec() on Linux and Android |
| 3.0.4.0 | 9 May 2013 | octal literals with the 0o prefix, e.g. 0o1234567 |
(Release dates are taken from the “Current version … from …” line on each archived home page. The 3.0.2.x and 3.0.3.x releases fell between captures and are not individually dated.)
3.0 was the turning point. Holetzeck rewrote the front end in Qt 4.2, released all of the code, and tested the result on Windows XP, Ubuntu 7.04 and openSUSE 10.2. The small MFC build (251 KB) stayed available for Windows users who did not want the 4.3 MB download that bundled the Qt 4.2 DLLs (by 2011 the Qt package had grown to 6.5 MB). By February 2008 the home page gave the licence as the GNU GPL, and the readme distributed with later versions specifies GPL version 3 “or (at your option) any later version”. The Free Software Directory, whose licence entries were checked in February 2009, lists the program with both GPLv2 and GPLv3.
The Android port came last. The readme explains that “the Kalkulon core is the same as for the desktop but GUI is written with Android framework in Java”, with the C++ interpreter compiled through the Android NDK. It needed Android 2.2 or later. On first start the app copied its help and example files into a Kalkulon folder on the SD card. The Android repository’s tags ran from “Beta 1.0.11” to “Release 2.3”, numbered separately from the desktop line. By 2013 the home page said simply that “Kalkulon is available for Windows, Linux and Android”. A Mac OS X build recipe existed too, but Holetzeck labelled it “not tested by me”.
Design Philosophy
Holetzeck described Kalkulon simply as a calculator “for programmers”. Its feature list (casts, shifts, hex and binary literals, 32-bit bitwise arithmetic) suggests he had in mind the kind of programmer who works with bitmasks, register values and hexadecimal dumps, though he never says so in as many words.
- Write it the way you would write it in C. The operator table is essentially C’s: arithmetic,
++/--,%, bitwise& | ^ ~, logical&& || !, shifts, all the compound assignments (+=through>>=), plus a**power operator and**=. Comments are/* */and//. - Integers are machine words. All numbers are stored as IEEE doubles, but bitwise operations, shifts and modulo “work on a 32-bit basis”, converting their operands to unsigned or signed 32-bit values as needed. Explicit casts such as
(u8),(s16)or(s32)(each with several spellings, e.g.u8,ub,byte) truncate the way a C programmer expects. - Everything is an expression. Control structures return values, a function body is a comma-separated list of expressions whose value is the last one, and the interactive session keeps every result in
out(the last answer) andoutl[i](the whole history). - One engine, several faces. The interpreter core is plain ISO C++, and the Windows MFC GUI, the Qt GUI, the console
kkcand the Android app are all front ends to it. Holetzeck also pointed developers tokkcas “an example of how to use the Kalkulon core as a simple math parser”.
Key Features
Data Types
The 2015 reference describes four kinds of value, and Type() reports which one you have:
| Type | Examples |
|---|---|
| Numbers | 1234, 2.5, 3.141e6, 0xAB10, 0b10011, 0o1234567 (added in 3.0.4.0, per the change log) |
| Strings | "Hello World!", joined with + |
| Lists | {1,2,3}, {3.141, "Pi", {99, 66, {33}, {}}}, indexed from zero: {44, {55, 66}}[1,1] == 66 |
| Pure functions | '1/#', '10*#', '#1*#2' |
User-Defined Functions and Scope
A function is defined by assignment, and its body is either a single expression or a parenthesised list of expressions:
| |
Variables assigned inside a function are local. To reach a global variable, Kalkulon borrows C++’s scope operator:
| |
Control Structures
There are four control structures, all written as function-like forms with semicolons separating their parts. All of them return a value:
| |
The reference shows five ways to write factorial, which together cover most of the language:
| |
Pure Functions and Functional Programming
Kalkulon’s most unusual feature for a calculator is the pure function: an anonymous function written in single quotes, with its arguments named # (or #1), #2, #3 and so on. Pure functions are ordinary values. They can be stored in variables or passed to other functions, and the @ operator applies one to an argument:
| |
A family of built-ins takes them as arguments: Table (build a list by evaluating a pure function over a range), ForEach, Fold and FoldList. FullForm exposes the internal form of an expression, and for the pure function '3+4*#' it prints <pure function 3 4 # * + END_1 >, which shows that the interpreter compiles expressions to postfix internally. The #-slot notation and the names Table, Fold, FoldList and FullForm are all shared with Mathematica, though Holetzeck’s documentation never mentions Mathematica or any other language as a model.
Programs, Scripts and the System
“Programs in Kalkulon are just a set of user defined functions and variable definitions”, in the reference’s words. They are kept in .k files and brought in with Load("name.k"). A file called autoload.k in the working directory is loaded at start-up. The console interpreter runs scripts directly and passes extra command-line arguments in an ARGV list:
| |
System built-ins include Print/PrintLn, a printf-style Sprintf (with a %b binary conversion), text and binary file I/O (ReadData, WriteData, ReadBinData, WriteBinData), Eval for evaluating a string, Exec for launching programs, GetTicks, Beep, and output-format switches such as SetHexFormat() and SetBinFormat() for showing results in other bases.
99 Bottles of Beer
This is the version Holetzeck submitted to the 99 Bottles of Beer collection (the entry is dated “06/07/05”), as preserved in an Internet Archive capture of July 2006:
| |
Two details stand out. The local variable bottles has the same name as the function containing it, which presumably works because Kalkulon keeps function names and variable names in separate namespaces (the reference does not say so explicitly). And Sprintf takes its arguments as a list, {bottles, s1}, instead of as a variable-length argument list.
Current Relevance
Kalkulon has been dormant since version 3.0.4.0 of 9 May 2013. The author’s site was captured with Kalkulon content into 2015 and 2016, but by March 2024 kalkulon.de served only a one-line “Hello, world!” page with a quotation from The Silmarillion. The Bitbucket repositories, both Mercurial, disappeared when Atlassian dropped Mercurial hosting in 2020, and no mirror on GitHub or elsewhere has been found.
What remains:
- heise download, the software archive of the German computing publisher Heise, still offers the 3.0.4.0 Windows build (about 7 MB, listed for Windows NT through Windows 7), with a note that the author no longer distributes it.
- The Free Software Directory still has its entry, pointing at the dead Bitbucket tarball.
- The Internet Archive holds copies of the online reference, the readme and change log, and the example scripts.
No Docker image or maintained build exists. Because the core is ordinary C++ with optional readline support, the console interpreter should in principle still build with a modern compiler, but without a surviving copy of the source that cannot be checked.
Why It Matters
Kalkulon is a small piece of history, but a typical one. Many programmers have written a calculator because the one that came with their operating system could not handle 0x1234 & 0x0F0F or a signed 8-bit cast. A few of those calculators kept going until they had variables, then functions, then loops, then list operations and file I/O, and by then their authors had written a programming language almost by accident. Kalkulon followed exactly that path, and its documentation records each step, from a 2006 freeware feature list to a 2013 GPL interpreter that ran the same C++ core on Windows, Linux and an Android phone.
It also shows how fragile one-person software is online. A complete, documented, open-source language with a decade of releases disappeared from the web after a hosting provider dropped support for a version-control system and a personal domain was repurposed. What survives does so mostly because a download archive and the Internet Archive kept copies.