Overload operator

Operators can be overloaded in XL by declaring the method operator$NAME_OF_OPERATOR(var , var ){}. The list of operators in groimp is available at: xl specification.

module A(float len) extends Sphere(0.1)
{
	public static boolean operator$com (A a) {
		return true;
	}
 
//	public static A operator$add (A a, int b) {
	public static A operator+ (A a, int b) {
 
		a.len += b;
		return a;
	}
 
       public void operator++(){
          ++this.len;
       }
}
 
public void run ()
{
	A a1 = new A();
	println(  ~a1  ); // print true
	println(  a1 + 1 ); // print a1 with a slightly bigger len
        ++a1; // increases a1.len by 1
}
 

A list with all object that currently use overloaded operators can be found here