Classes
The concept of creating instances of classes with access to member variables and methods is common across languages.
Create a class with
class start
. It takes in, at the very least, the name of the class (in PascalCase as with functions). You can then also provide extends
and a name of a class to indicate a single class to inherit from.End it with
class end
.class start : Word
comment line : ...
class end
class start : Noun extends Word
comment line : ...
class end
In C#:
class Word
{
// ...
}
class Noun : Word
{
// ...
}
In Python:
class Word:
# ...
class Noun(Word):
# ...
Constructors, or initialization methods, are called when a new instance of a class is created. It's declared with
constructor start
, which takes the publicity of the constructor, the name of the class, and any number of (name, type) arguments, and constructor end
.Inherited classes that define a constructor must provide an additional
base
argument along with any parameters to call to their parent class' constructor.class start : Noun extends Word
constructor start : public Noun name string base
print : { concatenate : ("Creating ") name }
constructor end
class end
In C#:
class Noun : Word
{
Noun(string name)
: base()
{
Console.WriteLine("Creating " + name);
}
}
In Python:
class Noun(Word):
def __init__(self, name):
super().__init__()
print("Creating " + name)
You can pass a reference to the current class using the
this
command.this
- In C#:
this
- In Python:
self
Create new instances of classes with the
new
command. It takes in the name of the class and any number of arguments to pass to the parameter.variable : fruit Noun { new : Noun "apple" }
- In C#:
Noun fruit = new Noun("apple");
- In Python:
fruit = Noun("apple")
You can export classes from the current file by including the
export
keyword before the class' name.class start : export Word
comment line : ...
class end
In C#:
public class Word
{
// ...
}
In Python:
class Word:
// ...
Last modified 3yr ago