-
Notifications
You must be signed in to change notification settings - Fork 1
Built‐in Types
Keyword int for long-signed integer type.
int anInt = 1;
Keyword float for 64-bit floating-point type.
float aFloat = 1.0;
bool aBool = true;
string aString = "hello";
string output = aString + " , world!"; # "hello, world!"
aString != output # true
Currently, the array-type in Eucleia can support multiple different object types. There is no option for the coder to create an array of a single type.
array anArray = [1, 2, 3];
anArray + [4] # [1, 2, 3, 4]
anArray[0] = 0; # [0, 2, 3, 4]
- Require built-in 'methods' to pop(), insert(), clear(), append() elements.
A struct can be defined in a similar way to C programs:
struct SomeStruct
{
int a;
float b;
string c;
};
struct SomeStruct instance;
instance.a = 1;
instance.b = 1.0;
instance.c = "hello";
A struct definition can extend an existing structure definition. The variable names defined in the parent cannot clash or be redefined.
struct AnotherStruct extends SomeStruct
{
string d;
};
Classes in Eucleia are very simple. Below is the example of a very simple class with a method to square its member variable. There are currently no init/deinit methods.
class SquareMe
{
func square()
{
return (num * num);
}
int num;
};
Similar to in C with structs, we require the keyword class followed by the class definition name and the instance name.
class SquareMe instance;
There are no private/protected members currently. To access/mutate a member variable or call a method, we use dot notation.
instance.num = 2;
print(instance.square()); # Expect 4.
To inherit from another class, use the keyword extends after the class definition name as in the example below. Methods and member variables in the parent class will be accessible in the child class. Currently, if the method name matches the name of a method in the parent class (even if the return types/arguments differ), it will override the definition in the parent class.
class Base
{
func printGreeting()
{
print("Hello from the base class!");
}
};
class Child extends Base
{
func printGreeting()
{
print("Hello from the child class!");
}
};
class Child instance;
instance.printGreeting() # Prints "Hello from the child class!"