Citrine (programming language): Difference between revisions

Content deleted Content added
m Updated latest version; fixed filename extension
Tags: Visual edit Mobile edit Mobile web edit
Minor refactoring for readability
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 77:
</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:
<syntaxhighlight lang="smalltalk">
Line 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 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 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">