Citrine (programming language): Difference between revisions

Content deleted Content added
Added another reference.
Line 2:
| name = Citrine
| logo = Citrine programming language logo.png
| paradigm = [[object Object-oriented|object programming|Object-oriented]], [[Prototype-based programming|prototype-based]]
| year = 2014
| designer = Gabor de Mooij
| developer = Gabor de Mooij
| latest release version = 0.2
| latest release date = {{startStart date and age|mf=yes|2014|df=y}}
| typing = [[dynamic typing|dynamic]]
| implementations = C
| influenced by = [[Smalltalk]] [[Self (programming language)|Self]]
| influenced =
| operating system = [[UNIXUnix]]
| license = [[BSD licenses|BSD]]
| website = http://{{URL|citrine-lang.org}}
| file ext = ctr
}}
 
'''Citrine''' is a general purpose [[programming language]] for UNIX[[Unix-like]] operating systems. The languageIt focuses on readability and maintainability.
Readability is achieved by syntacticalsyntactic and conceptual minimalism. The Citrine programming language is heavily inspired by [[Smalltalk]] and [[Self (programming language)|Self]] but has some very distinctive
features. Like Smalltalk, the Citrine language 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 [[JavascriptJavaScript]] because it uses [[Prototype-based programming|prototypes]]. The combination of Smalltalk like messages and prototypes is what makes Citrine unique.
Citrine unique.
 
== Syntax ==
 
Citrine has a very limited syntax and it's very closely related to Smalltalk. Everything in Citrine is an '''Object'object'', there are 5 literals:
 
<source lang="citrine">
Line 36 ⟶ 35:
</source>
 
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, comments start with a '#'.
Line 48 ⟶ 47:
</source>
 
This is called a '''unary''' message becausbecause it doestakes not take anyno arguments. A '''binary''' message is always a single UTF-8 character; (this is differentdiffers
from Smalltalk, where there is a fixfixed set of binary messages),. hereHere is an example:
 
<source lang="citrine">
Line 56 ⟶ 55:
 
Here a binary message '+' is send to number 6, the argument of this binary message is '7', this will result in a new number object '13'.
To assignAssigning the outcome of this operation to a variable one uses the assignment operator: :=.
 
<source lang="citrine">
Line 62 ⟶ 61:
</source>
 
Also note that each line in a Citrine program ends with a dot, just like in Smalltalk. Besides unary and binary messages, Citrine
also offers '''keyword messages''', these messageswhich take arguments interspersed with the message itself just like Smalltalk and [[Objective-C]].
 
<source lang="citrine">
Line 69 ⟶ 68:
</source>
 
The code snippet above will return a boolean object '''True'''.
 
== Control Flowflow ==
 
Just like Smalltalk, control flow in Citrine is implemented by strategic use of messages. For instance, to writewriting a conditional statement, one has torequires sendsending a block of code
to a boolean.
 
Line 92 ⟶ 91:
</source>
 
To break out of a loop in Citrine one has to send the message 'break' to a boolean, this allows a conditional break from a loop without having to factor out the break conditions:
without having to factor out the break conditions:
<source lang="citrine">
Line 106 ⟶ 104:
 
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, this allows developerswriting to write UNIXUnix-like '''[[Pipeline (Unix)|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...'.
 
Line 122 ⟶ 120:
</source>
 
OneThis object can makebe thismade objectto respond to messages by ordering the object to listen to events,. thisThis is kind of similar to
adding methods in languages like [[Java (programming language)|Java]]:
 
<source lang="citrine">
Line 131 ⟶ 129:
</source>
 
As hasstated been mentioned in this articleabove, inheritance is based on prototypes.
To derive an object from another object, onethe hasnew tomessage sendmust thebe new messagesent to the object
to be extended:
one wishes to extend:
 
<source lang="citrine">
Line 150 ⟶ 148:
== 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:
Line 169 ⟶ 167:
 
Citrine uses [[dynamic scoping]] instead of [[lexical scoping]], this means there is no need
for [[Dependencydependency Injection]] or global variables, but it might be harder to reason about than
lexical scope. This is similar as in programming language like
[[EMACS Lisp]] and [[BASIC]]. In code blocks the '''var''' keyword needs to be used to declare
a local variable.
 
Line 184 ⟶ 182:
 
==See also==
* [[Smalltalk (programming language)|Smalltalk]] - Smalltalk programming language
 
==References==
Line 193 ⟶ 191:
 
==External links==
* [http://{{Official website|citrine-lang.org Citrine homepage], Citrine homepage}}
* [https://github.com/gabordemooij/citrine source code], Source code on github