Citrine (programming language)

Last updated
Citrine
Citrine programming language logo.png
Paradigm Object-oriented, prototype-based
Designed by Gabor de Mooij, Aavesh Jilani
Developer Gabor de Mooij, Aavesh Jilani
First appeared2014
Stable release
0.9.6 / January 5, 2024;30 days ago (2024-01-05)
Typing discipline dynamic
OS Cross-platform (multi-platform)
License BSD
Filename extensions .ctr
Website citrine-lang.org
Major implementations
C
Influenced by
Smalltalk, Self

Citrine is a general-purpose programming language for Cross-platform (multi-platform) 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.

Contents

As of the 0.7 version Citrine has focused on supporting native human languages instead of just English to help people reduce the number of bugs because of confusion and misunderstanding due to language barriers. As such Citrine 0.7 and higher feature a translator to translate between human languages.

Syntax

Citrine has a very limited syntax and it's very closely related to Smalltalk. Everything in Citrine is an object, there are 5 literals:

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 '#'.

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.

5even?

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:

6+7.

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: :=.

total:=money+debt.

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.

x:=Numberbetween:1and:5.

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.

(money>price) true: { write:'Yes, you can afford this'. }. 

Likewise, a for-loop is written as:

{ :stepwrite:'this is step:'+step. } ×10.

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:

{ :i   (i=3) break.write:i. } *5.

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...'.

onesAndZeroes:='1o1o1o1o1o1'split:'o',map:mapUp,join:'0'.

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:

cat:=Objectnew.

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:

caton:'meow'do: {    Penwrite:'meow!'. }. 

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:

Animal:=Objectnew.Animalon:'makeSound'do: {  write:'?'. }. Cat:=Animalnew.Caton:'makeSound'do: {  write:'meow!'. }. Tom:=Catnew.TommakeSound.

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:

'text'length.

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

'text'bytes.

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:

Application:= {    mailer:=Mailernew.modulerun. }. 

See also

Related Research Articles

<span class="mw-page-title-main">String (computer science)</span> Sequence of characters, data type

In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed. A string is generally considered as a data type and is often implemented as an array data structure of bytes that stores a sequence of elements, typically characters, using some character encoding. String may also denote more general arrays or other sequence data types and structures.

<span class="mw-page-title-main">Smalltalk</span> Object-oriented programming language released first in 1972

Smalltalk is a purely object oriented programming language (OOP) that was originally created in the 1970s for educational use, specifically for constructionist learning, but later found use in business. It was created at Xerox PARC by Learning Research Group (LRG) scientists, including Alan Kay, Dan Ingalls, Adele Goldberg, Ted Kaehler, Diana Merry, and Scott Wallace.

In computing, serialization is the process of translating a data structure or object state into a format that can be stored or transmitted and reconstructed later. When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward. Serialization of object-oriented objects does not include any of their associated methods with which they were previously linked.

UTF-8 is a variable-length character encoding standard used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode Transformation Format – 8-bit.

<span class="mw-page-title-main">Self (programming language)</span> Prototype-based programming language

Self is an object-oriented programming language based on the concept of prototypes. Self began as a dialect of Smalltalk, being dynamically typed and using just-in-time compilation (JIT) as well as the prototype-based approach to objects: it was first used as an experimental test system for language design in the 1980s and 1990s. In 2006, Self was still being developed as part of the Klein project, which was a Self virtual machine written fully in Self. The latest version is 2017.1 released in May 2017.

In computer science, primitive data types are a set of basic data types from which all other data types are constructed. Specifically it often refers to the limited set of data representations in use by a particular processor, which all compiled programs must use. Most processors support a similar set of primitive data types, although the specific representations vary. More generally, "primitive data types" may refer to the standard data types built into a programming language. Data types which are not primitive are referred to as derived or composite.

Non-English-based programming languages are programming languages that do not use keywords taken from or inspired by English vocabulary.

<span class="mw-page-title-main">C syntax</span> Set of rules defining correctly structured programs

The syntax of the C programming language is the set of rules governing writing of software in C. It is designed to allow for programs that are extremely terse, have a close relationship with the resulting object code, and yet provide relatively high-level data abstraction. C was the first widely successful high-level language for portable operating-system development.

<span class="mw-page-title-main">ActionScript</span> Object-oriented programming language created for the Flash multimedia platform

ActionScript is an object-oriented programming language originally developed by Macromedia Inc.. It is influenced by HyperTalk, the scripting language for HyperCard. It is now an implementation of ECMAScript, though it originally arose as a sibling, both being influenced by HyperTalk. ActionScript code is usually converted to byte-code format by a compiler.

In computer science, dynamic dispatch is the process of selecting which implementation of a polymorphic operation to call at run time. It is commonly employed in, and considered a prime characteristic of, object-oriented programming (OOP) languages and systems.

F-Script is an object-oriented scripting programming language for Apple's macOS operating system developed by Philippe Mougin. F-Script is an interactive language based on Smalltalk, using macOS's native Cocoa API.

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.

<span class="mw-page-title-main">JavaScript syntax</span> Set of rules defining correctly structured programs

The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.

A class in C++ is a user-defined type or data structure declared with any of the keywords class, struct or union that has data and functions as its members whose access is governed by the three access specifiers private, protected or public. By default access to members of a C++ class declared with the keyword class is private. The private members are not accessible outside the class; they can be accessed only through member functions of the class. The public members form an interface to the class and are accessible outside the class.

Action Message Format (AMF) is a binary format used to serialize object graphs such as ActionScript objects and XML, or send messages between an Adobe Flash client and a remote service, usually a Flash Media Server or third party alternatives. The Actionscript 3 language provides classes for encoding and decoding from the AMF format.

BSON is a computer data interchange format. The name "BSON" is based on the term JSON and stands for "Binary JSON". It is a binary form for representing simple or complex data structures including associative arrays, integer indexed arrays, and a suite of fundamental scalar types. BSON originated in 2009 at MongoDB. Several scalar data types are of specific interest to MongoDB and the format is used both as a data storage and network transfer format for the MongoDB database, but it can be used independently outside of MongoDB. Implementations are available in a variety of languages such as C, C++, C#, D, Delphi, Erlang, Go, Haskell, Java, JavaScript, Julia, Lua, OCaml, Perl, PHP, Python, Ruby, Rust, Scala, Smalltalk, and Swift.

<span class="mw-page-title-main">Go (programming language)</span> Programming language

Go is a statically typed, compiled high-level programming language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It is syntactically similar to C, but also has memory safety, garbage collection, structural typing, and CSP-style concurrency. It is often referred to as Golang because of its former domain name, golang.org, but its proper name is Go.

MessagePack is a computer data interchange format. It is a binary form for representing simple data structures like arrays and associative arrays. MessagePack aims to be as compact and simple as possible. The official implementation is available in a variety of languages such as C, C++, C#, D, Erlang, Go, Haskell, Java, JavaScript (NodeJS), Lua, OCaml, Perl, PHP, Python, Ruby, Rust, Scala, Smalltalk, and Swift.

Universal Binary JSON (UBJSON) is a computer data interchange format. It is a binary form directly imitating JSON, but requiring fewer bytes of data. It aims to achieve the generality of JSON, combined with being much easier to process than JSON.

References