Content deleted Content added
Gabordemooij (talk | contribs) |
→Syntax: grammatical number; notation |
||
(63 intermediate revisions by 25 users not shown) | |||
Line 1:
{{short description|Programming language}}
{{Multiple issues|{{primary sources|date=August 2020}}{{COI|date=September 2020}}}}
{{Infobox programming language
| name = Citrine
| logo = Citrine programming language logo.png
| paradigm = [[
| year = 2014
| designer = Gabor de Mooij, Aavesh Jilani
| developer = Gabor de Mooij, Aavesh Jilani
| latest release version = 0.
| latest release date = {{
| typing = [[dynamic typing|dynamic]]
| implementations = C
| influenced by = [[Smalltalk]], [[Self (programming language)|Self]]
| influenced =
| operating system = [[
| license = [[BSD licenses|BSD]]
| website =
| file ext = .ctr
}}
'''Citrine''' is a general-purpose [[programming language]] for [[Cross-platform|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 (programming language)|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 [[Prototype-based programming|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:
* {{code|Nil}}
* {{code|True, False}}
* {{code|0,1,2,3}}
* {{code|'String'}}
* <code>{ ...params.. ...block of code... }</code>
The code block literal uses a
parameters, the backslash should be used instead
Citrine only supports full
A Citrine program is basically a sequence of messages sent to objects
<
5 even?
</syntaxhighlight>
This is called a
<
6 + 7.
</syntaxhighlight>
Here a binary message '+' is
<
total := money + debt.
</syntaxhighlight>
<
</syntaxhighlight>
The code snippet above will return a boolean object
==
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.
<syntaxhighlight lang="smalltalk">
(money > price) true: { ✎ write: 'Yes, you can afford this'. }.
</syntaxhighlight>
Likewise, a for-loop is written as:
<
</syntaxhighlight>
To break out of a loop in Citrine, one
<
{ :i
(i = 3) break.
} * 5.
</syntaxhighlight>
==
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 ''[[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...'.
<syntaxhighlight lang="smalltalk">
onesAndZeroes := '1o1o1o1o1o1' split: 'o', map: mapUp, join: '0'.
</syntaxhighlight>
==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.
</syntaxhighlight>
<
cat on: 'meow' do: {
Pen write: 'meow!'.
}.
</syntaxhighlight>
As
<
☞ Animal := Object new.
Animal on: 'makeSound' do: {
}.
☞ Cat := Animal new.
Cat on: 'makeSound' do: {
}.
☞ Tom := Cat new.
Tom makeSound.
</syntaxhighlight>
==
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:
<syntaxhighlight lang="smalltalk">
'text' length.
</syntaxhighlight>
returns the length of the string in UTF-8 code points, while:
<
'text' bytes.
</syntaxhighlight>
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:
<syntaxhighlight lang="smalltalk">
Application := {
☞ mailer := Mailer new.
module run.
}.
</syntaxhighlight>
==See also==
* [[
==References==
* [http://fll.presidentbeef.com/lang/citrine/ demo in new programming languages community]
* [https://jaxenter.com/citrine-a-new-all-purpose-programming-language-for-unixoid-systems-123558.html Citrine Review Jaxenter]
* [https://www.reddit.com/r/programming/comments/42gqu4/new_programming_language_citrine/ Announcement on Reddit]
* [http://www.infoworld.com/article/3028559/application-development/citrine-borrows-from-ruby-javascript-c-for-object-oriented-programming.html InfoWorld interview]
* [https://web.archive.org/web/20221108082728/https://www.tiobe.com/tiobe-index/ Tiobe Index]
==External links==
*
* [https://github.com/gabordemooij/citrine source code], Source code on
<!--Interwikies-->
<!--Categories-->
[[Category:Smalltalk programming language family]]
[[Category:Procedural programming languages]]
|