Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Citrine (programming language)

From Wikipedia, the free encyclopedia
Programming language
This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages)
icon
This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources.
Find sources: "Citrine" programming language – news ·newspapers ·books ·scholar ·JSTOR
(August 2020) (Learn how and when to remove this message)
A major contributor to this article appears to have aclose connection with its subject. It may require cleanup to comply with Wikipedia's content policies, particularlyneutral point of view. Please discuss further on thetalk page.(September 2020) (Learn how and when to remove this message)
(Learn how and when to remove this message)
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; 22 months ago (2024-01-05)
Typing disciplinedynamic
OSCross-platform (multi-platform)
LicenseBSD
Filename extensions.ctr
Websitecitrine-lang.org
Majorimplementations
C
Influenced by
Smalltalk,Self

Citrine is a general-purposeprogramming language forvarious operating systems. It focuses on readability and maintainability. Readability is achieved by syntactic and conceptual minimalism. The language is heavily inspired bySmalltalk andSelf 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 andJavaScript because it usesprototypes. 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

[edit]

Citrine has a very limited syntax very closely related to Smalltalk. Everything in Citrine is anobject. There are 5 literals:

  • Nil
  • True, False
  • 0,1,2,3
  • 'String'
  • { ...params.. ...block of code... }

The code block literal uses apipe symbol ⟨|⟩ to separate the parameters from the logic; if there are noparameters, 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.

5even?

This is called aunary message, because it takes no arguments. Abinary 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 offerskeyword messages, which take arguments interspersed with the message itself just like Smalltalk andObjective-C.

x:=Numberbetween:1and:5.

The code snippet above will return a boolean objectTrue.

Control flow

[edit]

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:

{:stepwrite:'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

[edit]

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-likepipelines. 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

[edit]

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:=Objectnew.

This object can be made to respond to messages by ordering the object to listen to events, similar to adding methods in languages likeJava:

caton:'meow'do: {Penwrite:'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:=Objectnew.Animalon:'makeSound'do: {write:'?'.}.Cat:=Animalnew.Caton:'makeSound'do: {write:'meow!'.}.Tom:=Catnew.TommakeSound.

Unicode

[edit]

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

[edit]

Citrine usesdynamic scoping instead oflexical scoping. Thus, there is no need fordependency injection or global variables, but it might be harder to reason about than lexical scope. This is similar in programming languages likeEmacs Lisp andBASIC. In code blocks thevar keyword needs to be used to declare a local variable.

The following demonstration makes the Mailer object available in the module:

Application:= {mailer:=Mailernew.modulerun.}.

See also

[edit]

References

[edit]

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=Citrine_(programming_language)&oldid=1209698031"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp