The Citrine Programming Language Project

Ѧ simple laחguagέ
ഽor ƩveЯyone


The Citrine Project aims to create a programming language that allows everyone to write code in their native language. By doing so, we hope to make programming more accessible and improve the quality of software.

☞ f := List ← 0 ; 1.

   ☞ a := f last.
   ☞ b := f second-last.   
   ☞ sum := a + b.

   ✎ write: sum.

   f add: sum.

} * 12.
Download Citrine 0.9 download citrine

The basics

In Citrine, everything is an object. A program in Citrine is a conversation between objects. Objects can talk to eachother by sending messages.

☞ x := 3.6 round.
☞ x := 3.6 round even?.

Here we send the message round to number 3.6 (which is an object), the resulting value (4) gets assigned to x (we use the hand and := for that). On the second line we chain two messages (round and even?), resulting in x = True. A keyword message is a message with arguments. The following code snippet shows how to draw a random number between 1 and 10 by sending the message between:and: to Number.

☞ x := Number between: 1 and: 10.

A message that is just one single symbol (+-/*) is a binary message and always has exactly one argument; the object that follows. In the following example we use binary message + to add numbers 2 and 3, resulting in x = 5.

☞ x := 2 + 3.

You can chain keyword messages using a comma (,):

✎ write: 'hello ', write: 'world'.
hello world

Control Flow

To execute block of code several times multiply the block:

{ :x ✎ write: x. } * 5.

This will run the block of code 5 times. If you want to break out of a loop, send the message break to a an expression that yields True or False. To create a condition:

(money ≥ price) true: {
   basket add: product.

You can catch errors by attaching a catch block to your code:

{  2 / 0. } catch:
{ :error ✎ write: error. }, run.
Division by zero.

Lists and Maps

To create a list of objects use:

☞ meals :=
List new
• 'hamburger'
• 'pizza'
• 'haggis'.

☞ todo := List ← 'dishes' ; 'cleaning'.

a Map allows you to associate keys with values:

☞ menu := Map new
Margherita: 11.90,
Hawaii: 12.99,
QuattroFormaggi: 13.00.

✎ write: ( menu ? 'Hawaii' ), stop.
✎ write: ( menu Margherita ), stop.


To create your own object:

Cat := Object new.

We now have our own cat! To make it possible to give our cat a name we need to define the following behaviour:

Cat on: 'name:' do: { :x 
 ⚿ identity := x.

Upon receiving the message name: followed by an actual name, this piece of code will assign the specified name to an internal property called identity. To indicate that this is an internal property, accessible only from within the object, we prefix it with a key symbol. Now we are ready to name our cat!

cat name: 'Diva'.

Our cat may be aware it's own name, but it has no means to tell us! So, we need to add that as well:

Cat on: 'name' do: {
 ↲ ⚿ identity.

Here we answer the message name with the name of the cat, stored in the internal property identity. So, to write the name of our cat on the screen, we can now ask the cat for its name like this:

✎ write: cat name.

Great! Now you area able to start writing your first Citrine program.
For advanced details see the FAQ.

How to translate?

To translate a Citrine program from one language into another:

ctr -t en2nl.dict myprogram.ctr

Dictionaries have the following format:


Use t for tokens and s for strings.
To generate a dictionary from 2 versions of Citrine in different languages:

ctr -g /nl/dictionary.h /en/dictionary.h

About Citrine

Citrine can be compiled in different languages. This means the core messages can be for instance English, Dutch, French or Icelandic. This allows Citrine to be used by a wider audience (i.e. schools). At time of writing, only English and Dutch versions are available. If you like to translate Citrine into your language, please contact me! While some language distributions are available on the download page, this site does not cover all different language versions (that would be too much work). The idea is that a Citrine ambassador will create and maintain a separate website for a language-specific distribution of Citrine.

What makes the Citrine project interesting?

Programming in your native language might help to better solve complex coding problems and improve code quality. It also allows non-technical people to read and help verify algorithms. Many programming languages have tried to make code more readable, writing programs in your native language can be considered a step in this direction. The Citrine project believes this is a difficult yet crucial step.

If Citrine respects all languages, why is this website in English?

As a developer, entrepeneur or scientist, you need to be able to read English texts. Citrine does not try to change that. However, writing complex programs in a foreign language is a different story. The Citrine project aims to reduce the number of mistakes in software by allowing everyone to use the language they know best. The manuals will still be mainly in English although translations in other languages may appear in the future or maybe summaries. The Citrine project also encourages ambassadors to host language specific implementations of Citrine along with translated manuals.

Is Citrine meant for non-programmers?

This is a common misunderstanding. Citrine is not meant for non-programmers. Citrine is and always will be a real general purpose programming language. However, even for professionals, programming in your native language reduces the number of mistakes. Citrine does try to make code as readable and maintainable as possible and helps to lower the barriers to programming for students and schools. However, Citrine is not an educational tool or a game to learn programming. In the end, Citrine is a full-fledged, powerful programming language that can be used for business purposes.

For more questions and answers, see the FAQ.

The Citrine Programming Language Project