The Cyan Programming Language



Cyan is a prototype-based statically-typed object-oriented language with many new and unique features. There is no class declaration as in C++, Java, Smalltalk, C#, Groovy, and other popular object-oriented languages. Instead, one can declare an object or prototype from which other objects are created. This makes the language easier to learn, define, and implement. More information on Cyan are available on the Cyan manual.


Many languages influenced the design of Cyan. The most important of them is Smalltalk followed by Omega, Self, Groovy, Green, and Java. Some details were taken from other languages such as Eiffel. However, the main novelties of Cyan were not based in any other language.


Cyan is a big language, not to say huge. A compiler is being built that will generate Java code. A small subset of the language has been implemented. Have that in mind when reading about the language.


Our goal in designing Cyan was to produce research articles. That is the same as to say that we do not expect it to be largely used. The language is a laboratory for creating and testing programming language features. In order of importance, in our view, the new features of Cyan are:

  1. grammar methods;
  2. an object-oriented exception handling system;
  3. context objects;
  4. statically-typed blocks;
  5. many ways of mixing dynamic and static typing (dynamic message sends, dynOnce, dynAlways);
  6. codegs;
  7. context blocks;
  8. literal objects delimited by user-defined symbols;
  9. generic prototypes with variable number of parameters;
  10. a restricted form of multi-methods (search for methods in the textually-declared order);
  11. a compilation strategy that considers previous version of the source code (source code in XML).

Some of these innovations make it easy to build Domain Specific Languages.

 

Some features that we believe Cyan will support in the future are:

  1. concurrent constructs;
  2. optional use of ; at the end of a statement;
  3. enumerated constants;
  4. metaobjects in the project program, so a metaobject can be applied to all prototypes of a program;
  5. a library of Domain Specific Languages for Graphical User Interface  made using grammar methods and based on Swing of Java (an initial version has been done already);
  6. a library for XML and HTML handling using DSL´s made using grammar methods;
  7. grammar methods with user-defined symbols. That would allow small parsers of arbitrary languages to be implemented as grammar methods;
  8. a library of patterns for parallel programming implemented as grammar methods;
  9. a library of patterns implemented using codegs, regular metaobjects, and literal objects;
  10. doc metaobject to document objects, methods, variables, and so on;
  11. literal regular expressions;
  12. generic methods.


Some features that Cyan may support in the future, although improbable, are:

  1. expanded objects (objects with value semantics, allocated in the stack)
  2. list comprehensions.

A prototype example


package program 

private object Box
    private Int n = 0 
    fun get -> Int { 
        ^ self.n 
    }
    fun set: Int n { 
        self.n = n 
    }
end 

object Program 
    public fun run {
        var s = Box clone; 
        var Int a; 
        a = In readInt; 
        s set: a; 
        Out writeln: (s get); 
    }
end
			

Java-like Interfaces


interface Printable 
    fun print 
end 

object Manager extends Person 
       implements Printable 
        // what he/she does 
    public var String profession 
    public fun print {
       ...
    } 
end
			

Hello World


package main

object Program
    public fun run {
        Out println: "Hello World"
    }
end
		

Creating new objects


var Person person; 
    // the same as "person = new Person()" in Java 
person = Person new; 
    // cloning the Person object 
person = Person clone;
person = Person();