ArticleslgStudy

science

Citrine (programming language)

Citrine (programming language) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Citrine (programming language) rather than just read about it. In short: Citrine is a general-purpose programming language for various operating systems. It focuses on readability and maintainability.

Key takeaways

  • Citrine (programming language) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Citrine (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Citrine (programming language) from memory before moving on to harder problems.

Reference excerpt

Citrine is a general-purpose programming language for various operating systems. It focuses on readability and maintainability. Readability is achieved by syntactic and conceptual minimalism. The language is heavily inspired by Smalltalk and Self but has some very distinctive features. Like Smalltalk, Citrine treats everything as an object and focuses on sending messages to these objects. However, unlike Smalltalk, Citrine lacks the concept of a class. In this regard, Citrine is more like Self and JavaScript because it uses prototypes. The combination of Smalltalk-like messages and prototypes is what makes Citrine unique. Since version 0.7, Citrine has focused on using forms based on various natural languages instead of just English, improving usability for users of other languages, thereby reducing programming effort and incidence of bugs. As such, Citrine 0.7 and later include a feature to transform code between natural languages.

Syntax Citrine has a very limited syntax very closely related to Smalltalk. Everything in Citrine is an object. There are 5 literals:

Nil True, False 0,1,2,3 'String' { ...params.. ...block of code... } The code block literal uses a pipe symbol ⟨|⟩ to separate the parameters from the logic; if there are no parameters, the backslash should be used instead. Citrine only supports full-line comments, which start with ⟨#⟩. A Citrine program is basically a sequence of messages sent to objects. For instance, to determine whether 5 is an even number, the message 'even?' is sent to the number 5.

This is called a unary message, because it takes no arguments. A binary message is always a single UTF-8 character; this differs from Smalltalk, where there is a fixed set of binary messages. Here is an example:

Here a binary message '+' is sent to number 6, with the argument of the binary message being '7'. This results in the new number object '13'. Assigning the outcome of this operation to a variable uses the assignment operator: :=.

Additionally, each line in a Citrine program ends with a dot, just as in Smalltalk. Along with unary and binary messages, Citrine offers keyword messages, which take arguments interspersed with the message itself just like Smalltalk and Objective-C.

The code snippet above will return a boolean object True.

Control flow Just like Smalltalk, control flow in Citrine is implemented by strategic use of messages. For instance, writing a conditional statement requires sending a block of code to a boolean.

Likewise, a for-loop is written as:

To break out of a loop in Citrine, one must send the message 'break' to a boolean. This allows a conditional break from a loop without having to factor out the break conditions:

Pipelines Unlike Smalltalk, Citrine has no semi-colon to send a message to the original receiver. Instead, Citrine has a comma token ',' used to chain keyword messages, which allows writing Unix-like pipelines. The following code uses a pipeline-like syntax to replace all the 'o' characters with zeroes, the resulting string would be something like: '1010101...'.

Prototypes The biggest difference from Smalltalk is the use of prototypes. Citrine does not have a concept of a class, but only knows about objects. An object is created using the new message:

This object can be made to respond to messages by ordering the object to listen to events, similar to adding methods in languages like Java:

As stated above, inheritance is based on prototypes. To derive an object from another object, the new message must be sent to the object to be extended:

Unicode Citrine uses UTF-8 unicode extensively, both objects and messages can consist of unicode symbols. All string length are calculated using UTF-8. Citrine distinguishes string length and size in bytes:

returns the length of the string in UTF-8 code points, while:

returns the number of bytes.

Scoping Citrine uses dynamic scoping instead of lexical scoping. Thus, there is no need for dependency injection or global variables, but it might be harder to reason about than lexical scope. This is similar in programming languages like Emacs Lisp and BASIC. In code blocks the var keyword needs to be used to declare a local variable. The following demonstration makes the Mailer object available in the module:

See also Smalltalk programming language

References demo in new programming languages community Citrine Review Jaxenter Announcement on Reddit InfoWorld interview Tiobe Index

External links Official website source code, Source code on GitHub

Worked examples

Example 1 — a first encounter with Citrine (programming language)

Start with the simplest possible case. Write down what Citrine (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Citrine (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Citrine (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Citrine (programming language)

In research
Citrine (programming language) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Citrine (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Citrine (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Procedural programming languages, Smalltalk programming language family, so understanding it makes those chapters shorter.
In everyday life
Look for Citrine (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Citrine (programming language)” →

How to study Citrine (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Citrine (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Citrine (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Citrine (programming language) in simple terms?

Citrine is a general-purpose programming language for various operating systems. It focuses on readability and maintainability.

Why does Citrine (programming language) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Citrine (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Citrine (programming language).

Tags

  • Procedural programming languages
  • Smalltalk programming language family

Keep exploring