The Citrine Programming Language Project

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


Welcome to the English/International Citrine Manual. back to homepage

Fibonacci sequence in Citrine:

☞ f := List ← 0 ; 1.

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

   ✎ write: sum.

   f add: sum.

} * 12.

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

More documentation

For further documentation regarding some advanced Citrine topics, please consult the Programmer's FAQ. For a complete manual of every command of the Citrine Programming Language, please consult the Full API documentation (English only).