-
Notifications
You must be signed in to change notification settings - Fork 5
CompaJ Lang
CompaJ uses Groovy underhood with some tweaks to reduce code size. You can learn groovy on it's official documentation.
By default all real numbers in Groovy are typed with BigDouble. But in CompaJ they are typed with double, you don't need to add d
suffix.
n = 5.0 // BigDouble in Groovy
n = 5.0 // double in CompaJ
CompaJ automatically erases type before variable creation. If you write something like this:
String myString = "someString"
It will be translated to Groovy as
myString = "someString"
But type wont be erased from class fields. So next example wont be changed during translation:
class MyClass {
private String myString
}
To create object in CompaJ use :
operator:
myModel = :BaseModel("MyModel")
You can omit braces if there is no arguments:
myModel = :BaseModel
ComapJ allows you to add methods to classes dynamically.
Local methods will be visible only after their definition. It means you can't you this methods in code above
. To create local methods use next syntax:
ClassName:::methodName(arg0, arg1, ...) { }
class MyClass {
void m() {
println "Hi"
}
}
/**
c = :MyClass
c.say("Hello") // Error! Method say is not yet defined!
**/
MyClass:::say(String s) {
println s
}
myClass = :MyClass
myClass.m() //Will print Hi
myClass.say("Hello") //Will print Hello
Global methods will be visible everywhere no matter where they are defined. To create global methods use next syntax:
ClassName::!methodName(arg0, arg1, ...) { }
class MyClass {
void m() {
println "Hi"
}
}
myClass = :MyClass
myClass.m() //Will print Hi
myClass.say("Hello") //Will print Hello
MyClass:::say(String s) {
println s
}