Est. 2003 Beginner

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

Paradigm Procedural expression language, with functional-programming built-ins (pure functions, Fold, Table)
Typing Dynamic
First Appeared around 2003
Latest Version 3.0.4.0 (9 May 2013)

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, do and 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.k file 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

VersionDateWhat changed
2.7.4.0before Oct 2006readline support for Linux builds of the console version
2.7.5.03 Oct 2006escape sequences \\, \", \n, \t in strings; printf-style %b binary formatting fixes
3.0.0.026 May 2007new Qt GUI for Windows and Linux; complete source released as free software
3.0.0.110 Nov 2007GUI fixes (help file path, options dialog); Windows binaries now built with Qt 4.3.2, according to the readme
3.0.0.27 Feb 2008SetRecursionLimit() (default 150) so runaway recursion no longer overflows the stack; licence stated as GNU GPL
3.0.1.026 Apr 2008matching parentheses and brackets highlighted while editing
3.0.1.422 Jan 2011locale fix needed under newer Qt; Mercurial repository on Bitbucket by mid-2011
3.0.2.0 – 3.0.3.02011–2013core ported to ARM/Android; GetTicks() on glibc; Exec() on Linux and Android
3.0.4.09 May 2013octal 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) and outl[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 kkc and the Android app are all front ends to it. Holetzeck also pointed developers to kkc as “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:

TypeExamples
Numbers1234, 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:

1
2
3
4
5
6
f() = 3; f(a) = 5*a; f(a,b) = a+b;
f()-f(10,4)          // -11

PI = 2*acos(0);
sin_deg(deg) = sin(deg/180*PI);
sin_deg(30)          // 0.5

Variables assigned inside a function are local. To reach a global variable, Kalkulon borrows C++’s scope operator:

1
2
3
factor = 5
f(n) = (factor=3, n*factor*::factor);
f(4)                 // 60 - local factor 3, global factor 5

Control Structures

There are four control structures, all written as function-like forms with semicolons separating their parts. All of them return a value:

1
2
3
4
5
if(condition; body)
if(condition; then_body; else_body)
while(condition; body)
do(body; condition)
for(init; condition; iterate; body)

The reference shows five ways to write factorial, which together cover most of the language:

1
2
3
4
5
6
7
8
// iterative (for n>=1)
fak1(n) = ( result=1, while(n; result=result*n--) );
fak2(n) = ( result=1, do(result=result*n; --n) );
fak3(n) = for(result=1, i=1; i<=n; i++; result=result*i);
// recursive (for n>=0)
fak4(n) = if(n<=1; 1; n*fak4(n-1));
// functional (n>=1)
fak5(n) = Fold(Table(n, '#'), 1, '#1*#2');

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:

1
2
3
4
pf = '1/#'
pf@(8)                   // 0.125
f(purefn, arg) = purefn@(arg)
f('10*#', 5)             // 50

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:

1
2
kkc /e:"3+4"                       evaluate one expression
kkc argv.k 66 8/9 {22,33} Hello    run a script with ARGV[1]..ARGV[4]

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* Kalkulon version of 99 Bottles of beer */
/* Juergen Holetzeck                      */
/* http://www.kalkulon.de                 */
/*                                        */
/* How to run:                            */
/* save as bottles.k                      */
/* run Kalkulon.exe                       */
/* type Load("bottles.k")                 */
/* type bottles(99)                       */
bottles(n)=
(
    s1 = "bottle(s) of beer on the wall",
    s2 = "bottle(s) of beer",
    s3 = "Take one down, pass it around,",
    f1 = "%i %s,",
    f2 = "%i %s.",
    bottles = n,
    while ( bottles > 0;
        PrintLn(Sprintf(f1, {bottles, s1})),
        PrintLn(Sprintf(f2, {bottles, s2})),
        PrintLn(s3),
        PrintLn(Sprintf(f2, {--bottles, s1}))
    )
);

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.

Timeline

2003
Earliest year in Kalkulon's copyright notices: every archived version of the home page and the online reference reads "© by Jürgen Holetzeck 2003" followed by the year of the update. No 2003 release itself survives in the Internet Archive
2005
Holetzeck submits a Kalkulon version of the 99 Bottles of Beer song to 99-bottles-of-beer.net, which files it as entry 740 under the category "real language"
2006
Version 2.7.5.0 (3 October 2006) is offered as Windows freeware for Windows 9x/ME, 2000/NT and XP, with a separate source package for the console interpreter kkc that also builds with gcc on Linux and supports the readline library
2007
Version 3.0.0.0 (26 May 2007) adds a new Qt 4.2 graphical interface for Windows and Linux and releases the complete source code as free and open source software; the older MFC-based Windows binary stays available as a 251 KB download
2008
Version 3.0.0.2 (7 February 2008) adds SetRecursionLimit() with a default limit of 150, and the home page now names the licence as the GNU GPL. Version 3.0.1.0 (26 April 2008) marks matching parentheses and brackets while editing
2011
Version 3.0.1.4 (22 January 2011) is distributed through heise.de and opendesktop.org; by June 2011 the home page also points to a public Mercurial repository on Bitbucket for the latest development version
2013
Version 3.0.4.0 (9 May 2013), the last release, adds octal literals with the 0o prefix. By mid-2013 the home page also offers an Android port on Google Play, with the C++ core compiled through the Android NDK beneath a Java user interface
2020
Atlassian removes Mercurial support from Bitbucket, and the Kalkulon desktop and Android repositories go with it; both URLs now return 404
2026
kalkulon.de serves only a placeholder page, but heise download still hosts the 3.0.4.0 Windows build, noting that the author no longer offers it

Running Today

Run examples using the official Docker image:

docker pull
Last updated: