Content deleted Content added
Gabordemooij (talk | contribs) |
→Syntax: grammatical number; notation |
||
(48 intermediate revisions by 19 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 4 ⟶ 6:
| paradigm = [[Object-oriented programming|Object-oriented]], [[Prototype-based programming|prototype-based]]
| year = 2014
| designer = Gabor de Mooij, Aavesh Jilani
| developer = Gabor de Mooij, Aavesh Jilani
| latest release version = 0.
| latest release date = {{Start date and age|
| typing = [[dynamic typing|dynamic]]
| implementations = C
| influenced by = [[Smalltalk]], [[Self (programming language)|Self]]
| influenced =
| operating system = [[
| license = [[BSD licenses|BSD]]
| website = {{URL|citrine-lang.org}}
| file ext = .ctr
}}
'''Citrine''' is a general
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
* {{code|Nil}}
Line 29 ⟶ 33:
* <code>{ ...params.. ...block of code... }</code>
The code block literal uses a ''pipe'' symbol ⟨|⟩ to separate the parameters from the logic
parameters, the backslash should be used instead
Citrine only supports full
A Citrine program is basically a sequence of messages sent to objects. For instance, to
<
5 even?
</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:
<
6 + 7.
</syntaxhighlight>
Here a binary message '+' is sent to number 6, with the argument of
<
total := money + debt.
</syntaxhighlight>
<
</syntaxhighlight>
The code snippet above will return a boolean object ''True''.
Line 63 ⟶ 67:
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)
</syntaxhighlight>
Likewise, a for-loop is written as:
<
</syntaxhighlight>
To break out of a loop in Citrine, one
▲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:
<
{ :i
} * 5.
▲ (i = 4) break.
</syntaxhighlight>
==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,
<
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,
<
cat := Object new.
</syntaxhighlight>
This object can be made to respond to messages by ordering the object to listen to events
<
cat on: 'meow' do: {
Pen write: 'meow!'.
}.
</syntaxhighlight>
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: {
}.
☞ Cat := Animal new.
Cat on: 'makeSound' do: {
}.
☞ Tom := Cat new.
Tom makeSound.
</syntaxhighlight>
==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.
</syntaxhighlight>
returns the length of the string in UTF-8 code
<
'text' bytes.
</syntaxhighlight>
returns the number of bytes.
Line 145 ⟶ 141:
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 := {
module run.
}.
</syntaxhighlight>
==See also==
Line 160 ⟶ 156:
* [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
* [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
<!--Interwikies-->
<!--Categories-->
[[Category:Smalltalk programming language family]]
[[Category:Procedural programming languages]]
|