Citrine (programming language): Difference between revisions

Content deleted Content added
mNo edit summary
Syntax: grammatical number; notation
 
(27 intermediate revisions by 9 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
Line 8:
| designer = Gabor de Mooij, Aavesh Jilani
| developer = Gabor de Mooij, Aavesh Jilani
| latest release version = 0.9.26
| latest release date = {{Start date and age|20202024|df=y1|5}}
| typing = [[dynamic typing|dynamic]]
| implementations = C
| influenced by = [[Smalltalk]], [[Self (programming language)|Self]]
| influenced =
| operating system = [[Cross-platform|Cross-platform (multi-platform)]]
| license = [[BSD licenses|BSD]]
| website = {{URL|citrine-lang.org}}
| file ext = .ctr
}}
 
'''Citrine''' is a general-purpose [[programming language]] for [[Cross-platform|Cross-platform (multi-platform)]]various operating systems developed by Gabor de Mooij and Aavesh Jilani.<ref>{{Cite web|title=About: Citrine (programming language)|url=https://dbpedia.org/page/Citrine_(programming_language)|access-date=2021-02-08|website=dbpedia]].org}}</ref> 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.<ref>{{Cite web|last=|first=|date=|title=demo in new programming languages community|url=http://fll.presidentbeef.com/lang/citrine/|url-status=live|archive-url=|archive-date=|access-date=|website=President Beef}}</ref>
 
AsSince of theversion 0.7 version, Citrine has focused on supportingusing nativeforms humanbased on various natural languages instead of just English, toimproving helpusability peoplefor reduceusers theof numberother oflanguages, bugsthereby becausereducing ofprogramming confusioneffort and misunderstandingincidence dueof to language barriersbugs. As such, Citrine 0.7 and higherlater featureinclude a translatorfeature to translatetransform code between humannatural languages.<ref>{{Cite web|date=2016-01-27|title=Citrine: A new all-purpose programming language for UNIXoid systems|url=https://jaxenter.com/citrine-a-new-all-purpose-programming-language-for-unixoid-systems-123558.html|access-date=2021-02-08|website=JAXenter|language=en-US}}</ref>
 
==Syntax==
Citrine has a very limited syntax and it's very closely related to Smalltalk. Everything in Citrine is an ''object'',. thereThere are 5 literals:
 
* {{code|Nil}}
Line 33:
* <code>{ ...params.. ...block of code... }</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 of '\'.
 
Citrine only supports full-line comments, commentswhich 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.
Line 44:
</syntaxhighlight>
 
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:
 
<syntaxhighlight lang="smalltalk">
Line 50:
</syntaxhighlight>
 
Here a binary message '+' is sent to number 6, with the argument of thisthe binary message isbeing '7',. thisThis will resultresults in athe new number object '13'. Assigning the outcome of this operation to a variable uses the assignment operator: :=.
 
<syntaxhighlight lang="smalltalk">
Line 56:
</syntaxhighlight>
 
Also note thatAdditionally, each line in a Citrine program ends with a dot, just likeas in Smalltalk. BesidesAlong with unary and binary messages, Citrine offers ''keyword messages'', which take arguments interspersed with the message itself just like Smalltalk and [[Objective-C]].
 
<syntaxhighlight lang="smalltalk">
Line 65:
 
==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.<ref>{{Cite web|last=|first=|date=|title=New programming language: Citrine|url=https://www.reddit.com/r/programming/comments/42gqu4/new_programming_language_citrine/|url-status=live|archive-url=|archive-date=|access-date=|website=Reddit}}</ref>
 
<syntaxhighlight lang="smalltalk">
Line 74:
 
<syntaxhighlight lang="smalltalk">
{ :step ✎ write: 'this is step:' + step. } *× 10.
</syntaxhighlight>
 
To break out of a loop in Citrine, one has tomust send the message 'break' to a boolean,. thisThis allows a conditional break from a loop without having to factor out the break conditions:
 
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:
<syntaxhighlight lang="smalltalk">
Line 88 ⟶ 87:
 
==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, thiswhich 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">
Line 95 ⟶ 94:
 
==Prototypes==
The biggest difference from Smalltalk is the use of prototypes. Citrine does not have a concept of a class, itbut only knows about objects. An object is created using the new message:
 
<syntaxhighlight lang="smalltalk">
Line 101 ⟶ 100:
</syntaxhighlight>
 
This object can be made to respond to messages by ordering the object to listen to events., Thissimilar isto kindadding ofmethods similarin tolanguages like [[Java (programming language)|Java]]:
adding methods in languages like [[Java (programming language)|Java]]:
 
<syntaxhighlight lang="smalltalk">
Line 132 ⟶ 130:
</syntaxhighlight>
 
returns the length of the string in UTF-8 code pointespoints, while:
 
<syntaxhighlight lang="smalltalk">
Line 141 ⟶ 139:
 
==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.<ref>{{Citation|last=Zaidi|first=Rehan|title=Object-Oriented Programming in JavaScript|date=2017|url=http://dx.doi.org/10.1007/978-1-4842-2220-1_8|work=JavaScript Essentials for SAP ABAP Developers|pages=111–125|place=Berkeley, CA|publisher=Apress|isbn=978-1-4842-2219-5|access-date=2021-02-08}}</ref>
 
The following demonstration makes the Mailer object available in the module:
Line 156 ⟶ 154:
 
==References==
* [http://fll.presidentbeef.com/lang/citrine/ demo in new programming languages community]
{{Reflist}}
* [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==
* {{Official website|citrine-lang.org}}
* [https://github.com/gabordemooij/citrine source code], Source code on githubGitHub
 
<!--Interwikies-->
 
<!--Categories-->
[[Category:Smalltalk programming language family]]
[[Category:Procedural programming languages]]
[[Category:Computer languages]]