Citrine (programming language)

Citrine
ParadigmObject-oriented, prototype-based
Designed byGabor de Mooij, Aavesh Jilani
DeveloperGabor de Mooij, Aavesh Jilani
First appeared2014
Stable release
0.9.6 / January 5, 2024; 9 months ago (2024-01-05)
Typing disciplinedynamic
OSCross-platform (multi-platform)
LicenseBSD
Filename extensions.ctr
Websitecitrine-lang.org
Major implementations
C
Influenced by
Smalltalk, Self

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.

5 even?

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 := Number between: 1 and: 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:

{ :step  write: '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 := Object new.

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:

cat on: 'meow' do: { 
  Pen write: '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 := Object new.
Animal on: 'makeSound' do: {
	 write: '?'.
}.
 Cat := Animal new.
Cat on: 'makeSound' do: {
	 write: 'meow!'.
}.
 Tom := Cat new.
Tom makeSound.

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 := Mailer new.
   module run.
}.

See also

References

Read other articles:

Emilio CigoliCigoli dalam Sunday in August (1950)LahirEmilio Cardi Cigoli(1909-11-18)18 November 1909Livorno, ItaliaMeninggal7 November 1980(1980-11-07) (umur 70)Roma, ItaliaPekerjaanPemeran, pengisi suara, pengarah pengalihan suaraTahun aktif1935-1980Anak2Orang tuaGiovanna Cigoli Emilio Cardi Cigoli (18 November 1909 – 7 November 1980) adalah seorang pemeran dan pengisi suara asal Italia.[1] Cigoli tampil dalam lebih dari 41 film dan 20 acara televisi antar...

 

 

العلاقات السورية الكوستاريكية سوريا كوستاريكا   سوريا   كوستاريكا تعديل مصدري - تعديل   العلاقات السورية الكوستاريكية هي العلاقات الثنائية التي تجمع بين سوريا وكوستاريكا.[1][2][3][4][5] مقارنة بين البلدين هذه مقارنة عامة ومرجعية للدولتين: وجه ...

 

 

Radio station in Fairborn, OhioWWSUFairborn, OhioBroadcast areaOhio collegeFrequency106.9 MHzBranding‘’Dayton’s Wright Choice’’ProgrammingFormatCollege radioOwnershipOwnerWright State UniversityHistoryFirst air date1976 (at 88.5), recognized by the FCC on April 4, 1977.[1]Call sign meaningWright State UniversityTechnical informationFacility ID73952ClassDERP26 wattsHAAT64.0 metersTransmitter coordinates39°46′58.00″N 84°3′43.00″W / 39.7827778°N 84.06...

Шалфей обыкновенный Научная классификация Домен:ЭукариотыЦарство:РастенияКлада:Цветковые растенияКлада:ЭвдикотыКлада:СуперастеридыКлада:АстеридыКлада:ЛамиидыПорядок:ЯсноткоцветныеСемейство:ЯснотковыеРод:ШалфейВид:Шалфей обыкновенный Международное научное наз...

 

 

Process for making objects from molten glass A bowl made from cast-glass. The two halves are joined together by the weld seam, running down the middle. Glass casting is the process in which glass objects are cast by directing molten glass into a mould where it solidifies. The technique has been used since the 15th century BCE in both Ancient Egypt and Mesopotamia. Modern cast glass is formed by a variety of processes such as kiln casting or casting into sand, graphite or metal moulds. History...

 

 

For the history of the Houston human spaceflight center, see Johnson Space Center § History. The Rockets moved into the Toyota Center at the start of the 2003–2004 season.[1] The Houston Rockets are an American professional basketball team based in Houston, Texas. The team plays in the Southwest Division of the Western Conference in the National Basketball Association (NBA). The team was established in 1967, and played in San Diego, California for four years, before moving to...

Television series This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: America's Heartland – news · newspapers · books · scholar · JSTOR (December 2015) (Learn how and when to remove this message) America's HeartlandPresented byJason Shoultz, Rob Stewart, Sarah Gardner, Dave Lieberman, Paul Robbins, Akiba HowardT...

 

 

Initiative of the Government of India National Solar Mission (NSM)Mission statementAchieve 100 GW solar capacity by 2022Type of projectSolar energy missionCountryIndiaPrime Minister(s)Manmohan Singh (2010–14)Narendra Modi (2014–present)MinistryMinistry of New and Renewable EnergyLaunched11 January 2010; 14 years ago (2010-01-11)Closed2022; 2 years ago (2022)(?) [citation needed] The National Solar Mission is an initiative of the Government of In...

 

 

National park in St. Louis, Missouri, U.S. Gateway Arch National ParkThe Gateway Arch serves as the attraction's centerpiece.LocationSt. Louis, Missouri, United StatesCoordinates38°37′29″N 90°11′06″W / 38.62460°N 90.18497°W / 38.62460; -90.18497Area90.9 acres (36.8 ha)EstablishedFebruary 22, 2018; 6 years ago (February 22, 2018)Visitors2,055,309 (in 2019)[1]Governing bodyNational Park ServiceWebsiteGateway Arch Nation...

土库曼斯坦总统土库曼斯坦国徽土库曼斯坦总统旗現任谢尔达尔·别尔德穆哈梅多夫自2022年3月19日官邸阿什哈巴德总统府(Oguzkhan Presidential Palace)機關所在地阿什哈巴德任命者直接选举任期7年,可连选连任首任萨帕尔穆拉特·尼亚佐夫设立1991年10月27日 土库曼斯坦土库曼斯坦政府与政治 国家政府 土库曼斯坦宪法 国旗 国徽 国歌 立法機關(英语:National Council of Turkmenistan) ...

 

 

WłostowaFloste ? Hilfe zu Wappen WłostowaFloste (Polen) WłostowaFloste Basisdaten Staat: Polen Woiwodschaft: Opole Powiat: Nysa Gmina: Korfantów Geographische Lage: 50° 30′ N, 17° 37′ O50.50055555555617.624166666667Koordinaten: 50° 30′ 2″ N, 17° 37′ 27″ O Höhe: 185–195 m n.p.m. Einwohner: 448 (31. März 2011[1]) Postleitzahl: 48-317 Telefonvorwahl: (+48) 77 Kfz-Kennzeichen: ONY Wirtschaft und Verkehr Nächster i...

 

 

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (مارس 2020) مركز سونينشتاين للقتل الرحيممعلومات عامةنوع المبنى مركز للقتل الرحيم[1] متحف المنطقة الإدارية بيرنا البلد  ألمانيا التفاصيل التقنيةجزء من عملية T4 — Hei...

1960 Summer Olympics sports venues Part of a series on 1960 Summer Olympics Venues Chronological summary Medal table (medallists) Paralympics IOC CONI vte For the 1960 Summer Olympics, a total of thirty-four sports venues were used. The Basilica of Maxentius, the Baths of Caracalla, the Appian Way, and Via Cassia were among the ancient Roman venues used for the games. The football stadium in Florence hosted the 1934 FIFA World Cup and would later host the 1990 FIFA World Cup. Stadio Olimpico ...

 

 

Regionalliga2018-19Datos generalesSede Alemania AlemaniaFecha 12 de julio de 201826 de mayo de 2019PalmarésCampeón VfL Wolfsburgo II (Nord)Chemnitzer FC (Nordost)SV Waldhof Mannheim (Südwest)FC Viktoria Köln (West)Bayern Múnich II (Bayern)Datos estadísticosParticipantes 90 equipos Intercambio de plazas Ascenso(s): Chemnitzer FCSV Waldhof MannheimFC Viktoria KölnBayern Múnich II Descenso(s): VfL OldenburgOberlausitz NeugersdorfBudissa BautzenStraelenKaan-MarienbornHerkenrathWieden...

 

 

Philosophy; Way of Living? New York headquarters, in former C Ledyard Blair carriage house[1] G. I. Gurdjieff's teaching and practice inspired the formation of many groups organized as Foundations, Institutes, and Societies many of which are now connected by the International Association of the Gurdjieff Foundations (IAGF).[2] After his death in 1949, the Gurdjieff Foundation Paris [3] was organized and led by Jeanne de Salzmann from the early 1950s, in cooperation wit...

Эта статья — о дворянском роде. О носителях фамилии см. Гинцбург. Гинцбурги (Günzburg) Описание герба: Щит, разделённый на четыре части. В первой части — рука, держащая флаг государства-сюзерена, во второй части — храм с его входом, в третьей — задняя часть храма, в ч...

 

 

Pour les articles homonymes, voir Schapiro. Ne doit pas être confondu avec Alexandre Schapiro. Alexandre SchapiroАлександр Петрович Шапиро (ru)Олександр Петрович Шапіро (uk) Naissance 11 octobre 1889 ou 6 août 1890Novozybkov Décès août 1942 (à environ 52 ans)Auschwitz Type de militance activistelutte arméejournaliste Cause défendue anarchismeanarcho-syndicalisme modifier  Alexandre Schapiro dit Sacha Schapiro, connu aussi s...

 

 

1984 studio album by Difford & TilbrookDifford & TilbrookStudio album by Difford & TilbrookReleasedJuly 1984Recorded1984StudioGood Earth Studios and Solid Bond Studios, London, UKGenreNew waveLength38:12LabelA&MProducerTony Visconti, E.T. Thorngren, Difford & TilbrookSqueeze chronology Singles – 45's and Under(1982) Difford & Tilbrook(1984) Cosi Fan Tutti Frutti(1985) Singles from Difford & Tilbrook Love's Crashing WavesReleased: June 1984 Hope Fell Down...

Medieval ruler of the Duchy of Normandy For the messenger pigeon, see Duke of Normandy (pigeon). Family tree of the early dukes of Normandy and Norman kings of England In the Middle Ages, the duke of Normandy was the ruler of the Duchy of Normandy in north-western France. The duchy arose out of a grant of land to the Viking leader Rollo by the French king Charles the Simple in 911. In 924 and again in 933, Normandy was expanded by royal grant. Rollo's male-line descendants continued to rule i...

 

 

Parliamentary constituency in the United Kingdom, 1832–1918 Clackmannanshire and Kinross-shireFormer county constituencyfor the House of CommonsSubdivisions of ScotlandClackmannanshire, Kinross-shire1832–1918SeatsOneCreated fromClackmannanshire and Kinross-shireReplaced byClackmannan & Eastern StirlingshireKinross & Western Perthshire Clackmannanshire and Kinross-shire was a constituency of the House of Commons of the Parliament of the United Kingdom from 1832 to 1918. From 1708 t...