Kitten is a minimalistic, dynamically typed, concatenative programming
language intended primarily for Web development. (This is an in-progress
implementation of that language.) Kitten is inspired by the Cat programming
language. The Kitten compiler (
kitten) compiles Kitten programs into C, which
can be compiled and linked against the Kitten runtime library (
produce a standalone executable. Thus a Kitten program can be built anywhere you
can find a C compiler, making it ideal for shared hosts, where installing
development tools may not be possible. Kitten will eventually come with a
standard prelude of definitions to make your development life easier. To build
the compiler, you need GHC and Parsec; the runtime, GCC. Just download the
sources and run
make with your fingers crossed. The sources also include a
shell script named
kittenc that you can use to compile a Kitten program
meow.kitten into an executable named
Kitten has three built-in types:
Integer: a signed 64-bit integral type.
Float: a double-precision floating-point number.
Quotation: a vector of boxed values, used to represent UTF-32 strings, heterogeneous arrays and structures, and anonymous functions.
The Kitten language itself is very simple:
<program> ::= <term>* <term> ::= <integer> | <float> | <quotation> | <word> | <string> | <definition> | <import> <integer> ::= [0-9]+ <float> ::= [0-9]+ '.' [0-9]+ <quotation> ::= '[' <term>* ']' <word> ::= [A-Za-z_][0-9A-Za-z_]* <string> ::= '"' [^"]* '"' <definition> ::= "define" <word> <quotation> <import> ::= "import" <string>
Comments are given in parentheses (
()), and can be nested.
All terms essentially denote functions, and juxtaposition of terms denotes function composition. Thus all expressions are written in terms of data flow only, i.e., completely point-free.
There are only two special forms in the language:
define, which introduces a
new word definition, and
import, which imports a Kitten file for compilation
into the final executable.
"Hello world!\n" write
(It is customary to give a comment alongside definitions briefly describing the expected inputs and outputs, of the form “inputs -- outputs”.) define join ([a] [b] -- [a b]) [compose] define greet (name --) ["Hello, " swap "!\n" join join] define prompt (prompt -- input) [write read_line] "What is your name? " prompt greet
The following definitions are provided by the Kitten runtime library.
[A] applyEvaluates the quotation at the top of the stack.
[A] [B] composeReturns the composition of the two quotations at the top of the stack.
A dupDuplicates the value at the top of the stack.
A [B] [C] ifApplies
Ais true (nonzero); otherwise, applies
A popDiscards the top value on the stack.
A B swapSwaps the two topmost values on the stack.
Arithmetic and Conditional
A B addReturns the sum of
A B divReturns the quotient of
A B eqReturns whether
A B geReturns whether
Ais greater than or equal to
A B gtReturns whether
Ais greater than
A isfReturns whether
Ais a float.
A isiReturns whether
Ais an integer.
A isqReturns whether
Ais a quotation.
A B leReturns whether
Ais less than or equal to
A B ltReturns whether
Ais less than
A B modReturns the modulus of
A B mulReturns the product of
A B neReturns whether
Ais not equal to
A B subReturns the difference of
Ato standard output as a character.
Ato standard output as a formatted value.
The following definitions are provided by the Kitten standard library:
read_lineReads a line of text into a quotation.