Content deleted Content added
No edit summary |
m →top: replaced: primitively-defined → primitively defined |
||
(26 intermediate revisions by 21 users not shown) | |||
Line 1:
{{Short description|None}}
{{primary sources|date=January 2017}}
Line 10 ⟶ 11:
| latest release version = 1.3.3
| latest release date = {{Start date and age|2017|08|21}}
| typing = [[
| scope =
| programming language =
Line 32 ⟶ 33:
| url=https://gitter.im/ceylon/user?at=5660a7242cbea1d7054de9d9
| title=ceylon/user - Gitter
| access-date=2015-12-04}}</ref> [[Lisp (programming language)|Lisp]],<ref>{{cite web
| url=https://gitter.im/ceylon/user?at=5660a90e5057376520db6f8b
| title=ceylon/user - Gitter
| access-date=2015-12-04}}</ref> [[Whiley (programming language)|Whiley]]<ref>{{cite web
| url=https://jaxenter.com/top-10-ceylon-language-features-java-wishes-it-had-108003.html
| access-date=2019-11-29
| title=Top 10 Ceylon language features Java wishes it had}}</ref>
| influenced =
| wikibooks =
}}
'''Ceylon'''
| url=http://ceylon-lang.org/blog/2013/09/22/ceylon-1/
| title=Ceylon 1.0 beta
Line 60 ⟶ 64:
| title=FAQ about language design: Goals
| access-date=2015-12-04}}</ref>
* A type system enforcing [[null safety]] and list element existence at compile time
* Regular syntax and semantics, avoiding special cases and primitively
* Support for generic programming and metaprogramming, with [[Reification (computer science)|reified]] [[Parametric polymorphism|generics]]
* Modularity built into the language, based on [[WildFly|JBoss modules]], interoperable with [[OSGi]]<ref>{{cite web
Line 79 ⟶ 83:
The name "Ceylon" is an oblique reference to Java, in that [[Java]] and [[Sri Lanka]], formerly known as Ceylon, are islands known for growth and export of [[coffee]] and [[tea]].
In August 2017, Ceylon was donated to the [[Eclipse Foundation]]. Development slowed down and finally stopped in 2020.<ref>{{cite web
|date=2020-05-25
|title= ceylon / ceylon
|publisher=GitHub, Inc.
|url=https://github.com/eclipse-archived/ceylon
|access-date=2024-01-22
|archive-url=https://web.archive.org/web/20231003075404/https://github.com/eclipse-archived/ceylon
|archive-date=2023-10-03
|url-status=live}}
</ref> In April 2023, [[Eclipse Foundation]] declared the termination of the transition.<ref>{{cite web
|date=2023-04-05
|title= Eclipse Ceylon™ Termination Review
|publisher=Eclipse Foundation
|url=https://projects.eclipse.org/projects/technology.ceylon/reviews/termination-review
|access-date=2023-04-23
|archive-url=https://web.archive.org/web/20230423134055/https://projects.eclipse.org/projects/technology.ceylon/reviews/termination-review
|archive-date=2023-04-23
|url-status=live}}</ref>
== Language features ==
Line 85 ⟶ 106:
=== Type system ===
One of the most novel aspects of Ceylon compared to Java is its [[type system]]. Ceylon foregoes Java's primitive types<ref>{{cite web|last1=King|first1=Gavin|title=Ceylon: Language Design FAQ|url=http://ceylon-lang.org/documentation/faq/language-design/}}</ref> and [[Object type|boxing]] in favor of a type system composed entirely of first-class objects. While this may cause boxing overhead in some situations, it makes the type system more uniform.
Ceylon allows for union and [[intersection type]]s, in a similar fashion to [[TypeScript]], [[Whiley (programming language)|Whiley]] and Flow, which in fact, took the idea from Ceylon.
Union types, written <code>A|B</code>, allow a variable to have more than one type. The following example shows a Ceylon function which may take either an [[Integer (computer science)|integer]] or a [[String (computer science)|string]]:
<
shared void integerOrString(Integer|String input) {
if (is Integer input) {
Line 99 ⟶ 120:
}
}
</syntaxhighlight>
Intersection types, written <code>A&B</code>, are the theoretical foundation of [[flow-sensitive typing]]:
<
shared void integerOrString(Integer|String input) {
Integer added = input + 6; // illegal; the + operator is not defined on Integer|String
Line 114 ⟶ 135:
}
}
</syntaxhighlight>
The condition <code>is Integer input</code> narrows the type of <code>input</code> to <code><Integer|String> & Integer</code>,
Line 122 ⟶ 143:
==== Null safety ====
Union and intersection types are used to provide [[null safety]].
The top type of the Ceylon type hierarchy is the class <code>Anything</code>,
which has two subclasses: <code>Object</code>, the superclass of all normal classes and all interfaces, and <code>Null</code>, with the only instance [[Null pointer|<code>null</code>]].
Line 134 ⟶ 155:
Intersection types can be used to get a non-optional type out of a possibly-optional type, such as a type parameter. For example, the signature of a function that removes <code>null</code> elements from a stream of values could be:
<
Iterable<Element&Object> removeNulls<Element>(Iterable<Element> stream);
</syntaxhighlight>
When <code>removeNulls</code> is called with a stream of <code>Integer|Null</code> elements, the result will be a stream of <code><Integer|Null> & Object</code> elements, which simplifies to <code>Integer</code>.
==== Functions ====
Similarly to many modern languages, Ceylon supports [[first class
<
// A top-level higher-order function using block syntax (not associated with any user-created classes)
String process(String text, String transformString(String toChange)) {
Line 158 ⟶ 179:
String reversed1 = process("one", reverse);
//
String reversed2 = process("one", (text) => text+text);
</syntaxhighlight>
==== Enumerated types ====
Similar to Java and many other languages, and with a similar mechanism as [[Algebraic data type|algebraic types]], Ceylon supports [[enumerated
<
// Traditional syntax for enumerated type, in this case, limiting the instances to three objects(for this purpose: Singletons)
abstract class Vehicle(shared String name) of plane | train | automobile {}
Line 189 ⟶ 210:
//shared new boat extends named("boat") {}
}
</syntaxhighlight>
==== Type inference ====
Ceylon is strongly and statically typed, but also has support for [[type inference]].
The <code>value</code> keyword is used to infer the type of a variable,
and the <code>function</code> keyword is used to infer the type of a function.
The following two definition pairs are each equivalent:
<
Integer i = 3;
value i = 3;
Line 207 ⟶ 228:
return i1 + i2;
}
</syntaxhighlight>
However, to make single-pass type inference possible, type inference is only allowed for non-toplevel and unshared declarations.<ref>{{cite web
Line 217 ⟶ 238:
=== Entry point with names===
By default the starter (<code>ceylon run</code>) runs the shared run() function of a module:
<
/* The classic Hello World program */
shared void run() {
print("Hello, World!");
}
</syntaxhighlight>
but any other shared function without parameters can be used as main calling the program with the
<code>ceylon run --compile=force --run hello default</code>
Line 249 ⟶ 270:
== License ==
All parts of Ceylon are available
| url=http://ceylon-lang.org/code/licenses
| title=Ceylon: Licenses
Line 274 ⟶ 295:
[[Category:2011 software]]
[[Category:High-level programming languages]]
[[Category:Source-to-source compilers]]
|