![]() | |
Paradigm | Object-oriented |
---|---|
Designed by | Gavin King |
Developer | Eclipse Foundation |
First appeared | 2011 |
Stable release | 1.3.3 / August 21, 2017 |
Typing discipline | Static, strong, safe |
Platform | Java virtual machine, JavaScript |
License | Apache License 2.0 |
Filename extensions | .ceylon [1] |
Website | ceylon-lang |
Influenced by | |
Java, [2] Scala, Smalltalk, ML, [3] Lisp, [4] Whiley [5] |
Ceylon was an object-oriented, strongly statically typed programming language with an emphasis on immutability, created by Red Hat. Ceylon programs run on the Java virtual machine (JVM), and could be compiled to JavaScript. [6] [7] The language design focuses on source code readability, predictability, toolability, modularity, and metaprogrammability. [8]
Important features of Ceylon include: [9]
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. [13] In April 2023, Eclipse Foundation declared the termination of the transition. [14]
Ceylon is heavily influenced by Java's syntax, but adds many new features.
One of the most novel aspects of Ceylon compared to Java is its type system. Ceylon foregoes Java's primitive types [15] and 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 types, in a similar fashion to TypeScript, Whiley and Flow, which in fact, took the idea from Ceylon.
Union types, written A|B
, allow a variable to have more than one type. The following example shows a Ceylon function which may take either an integer or a string:
sharedvoidintegerOrString(Integer|Stringinput){if(isIntegerinput){print("Got the integer ``input``");}else{print("Got the string '``input``'");}}
Intersection types, written A&B
, are the theoretical foundation of flow-sensitive typing:
sharedvoidintegerOrString(Integer|Stringinput){Integeradded=input+6;// illegal; the + operator is not defined on Integer|Stringif(isIntegerinput){Integeradded=input+6;// legal; input is now known to be an Integerprint("Got the integer ``input``");}else{print("Got the string '``input``'");}}
The condition is Integer input
narrows the type of input
to <Integer|String>& Integer
, which distributes to Integer&Integer | String&Integer
, which, as String
and Integer
are disjoint types, is equivalent to Integer&Integer | Nothing
(Nothing
is the empty bottom type), which simplifies to just Integer
.
Union and intersection types are used to provide null safety. The top type of the Ceylon type hierarchy is the class Anything
, which has two subclasses: Object
, the superclass of all normal classes and all interfaces, and Null
, with the only instance null
. Since Object
and Null
are disjoint types, most regular types like Integer
or List<String>
are not nullable; a nullable type is the union Integer|Null
, abbreviated Integer?
. [16]
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 null
elements from a stream of values could be:
Iterable<Element&Object>removeNulls<Element>(Iterable<Element>stream);
When removeNulls
is called with a stream of Integer|Null
elements, the result will be a stream of <Integer|Null> & Object
elements, which simplifies to Integer
.
Similarly to many modern languages, Ceylon supports first class functions and higher order functions, including function types and anonymous functions [17]
// A top-level higher-order function using block syntax (not associated with any user-created classes)Stringprocess(Stringtext,StringtransformString(StringtoChange)){returntransformString(text);}// A top-level function calling String.reverse in expression form.Stringreverse(Stringtext)=>text.reversed;// A function reference to String.reversed but mostly equivalent to the function above.String(String)reverseFunctionReference=String.reversed;// An example where the top-level function above is provided as an argument to the higher-order function aboveStringreversed1=process("one",reverse);// An example where an anonymous function - (text) => text+text - is provided to the higher-order function above. Stringreversed2=process("one",(text)=>text+text);
Similar to Java and many other languages, and with a similar mechanism as algebraic types, Ceylon supports enumerated types, otherwise known as enums. This is implemented in Ceylon with a pattern of limiting the instances of an abstract class at declaration to a limited set of objects (in this case, singleton instances). Another way to implement this pattern is with the new constructor feature in Ceylon 1.2 where the objects are implemented as different named constructor declarations. [18]
// Traditional syntax for enumerated type, in this case, limiting the instances to three objects(for this purpose: Singletons)abstractclassVehicle(sharedStringname)ofplane|train|automobile{}objectplaneextendsVehicle("plane"){}objecttrainextendsVehicle("train"){}objectautomobileextendsVehicle("automobile"){}// Compile error: type is not a subtype of any case of enumerated supertype: 'boat' inherits 'Vehicle'//object boat extends Vehicle("boat") {}// New (as of Ceylon 1.2.0) constructor-based syntaxclassVehicleofplane|train|automobile{Stringname;abstractnewnamed(StringpName){name=pName;}sharednewplaneextendsnamed("plane"){}sharednewtrainextendsnamed("train"){}sharednewautomobileextendsnamed("automobile"){}// Compile error: value constructor does not occur in of clause of non-abstract enumerated class: 'boat' is not listed in the of clause of 'Vehicle'//shared new boat extends named("boat") {}}
Ceylon is strongly and statically typed, but also has support for type inference. The value
keyword is used to infer the type of a variable, and the function
keyword is used to infer the type of a function. The following two definition pairs are each equivalent:
Integeri=3;valuei=3;Integeradd(Integeri1,Integeri2){returni1+i2;}functionadd(Integeri1,Integeri2){returni1+i2;}
However, to make single-pass type inference possible, type inference is only allowed for non-toplevel and unshared declarations. [19]
By default the starter (ceylon run
) runs the shared run() function of a module:
/* The classic Hello World program */sharedvoidrun(){print("Hello, World!");}
but any other shared function without parameters can be used as main calling the program with the run parameter, like this:
ceylon run --compile=force --run hello default
Versions of Ceylon released: [20]
All parts of Ceylon are available as free software, mostly the Apache License. [21] Part of the source code is licensed under LGPL.
PHP is a general-purpose scripting language geared towards web development. It was originally created by Danish-Canadian programmer Rasmus Lerdorf in 1993 and released in 1995. The PHP reference implementation is now produced by the PHP Group. PHP was originally an abbreviation of Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor.
In computer programming, a parameter or a formal argument is a special kind of variable used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are the values of the arguments with which the subroutine is going to be called/invoked. An ordered list of parameters is usually included in the definition of a subroutine, so that, each time the subroutine is called, its arguments for that call are evaluated, and the resulting values can be assigned to the corresponding parameters.
The syntax of the C programming language is the set of rules governing writing of software in C. It is designed to allow for programs that are extremely terse, have a close relationship with the resulting object code, and yet provide relatively high-level data abstraction. C was the first widely successful high-level language for portable operating-system development.
printf is a C standard library function that formats text and writes it to standard output.
Apache Groovy is a Java-syntax-compatible object-oriented programming language for the Java platform. It is both a static and dynamic language with features similar to those of Python, Ruby, and Smalltalk. It can be used as both a programming language and a scripting language for the Java Platform, is compiled to Java virtual machine (JVM) bytecode, and interoperates seamlessly with other Java code and libraries. Groovy uses a curly-bracket syntax similar to Java's. Groovy supports closures, multiline strings, and expressions embedded in strings. Much of Groovy's power lies in its AST transformations, triggered through annotations.
In computer science, type conversion, type casting, type coercion, and type juggling are different ways of changing an expression from one data type to another. An example would be the conversion of an integer value into a floating point value or its textual representation as a string, and vice versa. Type conversions can take advantage of certain features of type hierarchies or data representations. Two important aspects of a type conversion are whether it happens implicitly (automatically) or explicitly, and whether the underlying data representation is converted from one representation into another, or a given representation is merely reinterpreted as the representation of another data type. In general, both primitive and compound data types can be converted.
This article compares two programming languages: C# with Java. While the focus of this article is mainly the languages and their features, such a comparison will necessarily also consider some features of platforms and libraries. For a more detailed comparison of the platforms, see Comparison of the Java and .NET platforms.
The syntax of Java is the set of rules defining how a Java program is written and interpreted.
In computer science, the Boolean is a data type that has one of two possible values which is intended to represent the two truth values of logic and Boolean algebra. It is named after George Boole, who first defined an algebraic system of logic in the mid 19th century. The Boolean data type is primarily associated with conditional statements, which allow different actions by changing control flow depending on whether a programmer-specified Boolean condition evaluates to true or false. It is a special case of a more general logical data type—logic does not always need to be Boolean.
In some programming languages, const is a type qualifier, which indicates that the data is read-only. While this can be used to declare constants, const in the C family of languages differs from similar constructs in other languages in that it is part of the type, and thus has complicated behavior when combined with pointers, references, composite data types, and type-checking. In other languages, the data is not in a single memory location, but copied at compile time for each use. Languages which use it include C, C++, D, JavaScript, Julia, and Rust.
The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.
In computer programming, an enumerated type is a data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language. An enumerated type can be seen as a degenerate tagged union of unit type. A variable that has been declared as having an enumerated type can be assigned any of the enumerators as a value. In other words, an enumerated type has values that are different from each other, and that can be compared and assigned, but are not specified by the programmer as having any particular concrete representation in the computer's memory; compilers and interpreters can represent them arbitrarily.
Haxe is a high-level cross-platform programming language and compiler that can produce applications and source code for many different computing platforms from one code-base. It is free and open-source software, released under an MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.
C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by the publication year of the specification, though it was formerly named C++0x because it was expected to be published before 2010.
In object-oriented computer programming, an extension method is a method added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension methods are features of some object-oriented programming languages. There is no syntactic difference between calling an extension method and calling a method declared in the type definition.
This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.
Kotlin is a cross-platform, statically typed, general-purpose high-level programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code via LLVM. Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.
Swift is a high-level general-purpose, multi-paradigm, compiled programming language created by Chris Lattner in 2010 for Apple Inc. and maintained by the open-source community. Swift compiles to machine code, as it is an LLVM-based compiler. Swift was first released in June 2014, and the Swift toolchain has shipped in Xcode since version 6, released in 2014.
Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level systems programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.
Whiley is an experimental programming language that combines features from the functional and imperative paradigms, and supports formal specification through function preconditions, postconditions and loop invariants. The language uses flow-sensitive typing also known as "flow typing."
A compilation unit is a text file, with the filename extension .ceylon
.
Ceylon is a new programming language that's deeply influenced by Java