1.6. Some "advanced" features

[Warning]Text not verified for kermeta 2

Kermeta implements several "less common" or advanced features that helps in many situations.

Typically, lambda expressions/functions is a well known concept, very useful in almost all kermeta code. Even, if you will probably not write your own function, you'll certainly use the existing one defined on collections.

1.6.1.  Functions in Kermeta

In order to implement and statically type check OCL-like iterators, Kermeta includes some limited functional features by implementing lambda expressions.

This is typically used on Collection which provides operations that uses a function as parameter. For example : each , select , forAll , detect ...

Example 1 : the following code will build a collection of names of the operations that start with "test".

var names : Collection<String>
names := self.getMetaClass.classDefinition.ownedOperation
            .select{ op | op.name.indexOf("test") == 0}
            .collect{ op | op.name }
	    

Example 2 : Providing a time function on Integer

operation times(body : <Integer->Object>) : Void is do
    from var i : Integer init 0
    until i == self
    loop
        body(i)
        i := i + 1
    end
end

this allows to write code like :

var res : Integer
10.times { i | stdio.writeln(i.toString + ": Hello") } // Say 10 times Hello

See sections " Lambda Expressions and functions " and Lambda Expression for detailed informations.

1.6.2. Other advanced features

1.6.2.2. Other technical features

As Kermeta language is implemented upon Eclipse and Java, you can call Java code inside Kermeta code.(see Section 2.24, “Using existing java code in Kermeta ” )

There is some special behavior regarding object comparison or cloning.