Live

Live Scripts

You can copy/paste any of the following scripts in the editor above, modify them if you want, and finally run them.

Hello World

Description: The ubiquitous hello world script.

"Hello World".println();

Variables and Control Flow

Description: A script that demonstrates defining and using variables and basic control flow constructs.

var i : Integer = 5;
if (i > 3) {
    for (j in 1.to(i)) {
      j.print();
      if (hasMore) ",".print();
    }
}

Model Querying

Description: A script that demonstrates the model querying facilities of EOL.

// In this script, we query Ecore to find out:

// ... how many classes it has
EClass.all.size().println("All classes: ");

// ... how many abstract classes it has
EClass.all.select(c|c.abstract)
    .size().println("Abstract classes: ");

// ... the names of its classes and how many 
// features each one has
"Class names: ".println();
for (c in EClass.all) {
    var toPrint = " " + c.name;
    toPrint = toPrint + "->" + 
        c.eStructuralFeatures.size();

    toPrint.println();
}

Operations

Description: This script defines and invokes an addHello() operation on strings.

"John".addHello().println();

operation String addHello() {
    return "Hello " + self;
}

Collections

Description: The script demonstrates defining a collection (sequence) and then filtering and navigating it through the built-in EOL operations.

var seq = Sequence{1..10};

seq.size().println();

seq.reject(i|i > 5).println();

seq.invert().println();

seq.collect(i|i*2).println();

Random

Description: This script demonstrates the random() operation that picks a random element of the collection on which it is invoked.

for (i in Sequence{1..5}) {
   EClass.all.random().name.println();
}

Delete

Description: This script demonstrates deleting model elements.

var randomClass = EClass.all.random();
EClass.all.size().println("Before delete: ");
delete randomClass;
EClass.all.size().println("After delete: ");