RosettaCodeData/Task/Classes/EMal/classes.emal

31 lines
857 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
type Bear ^| the type system is informed about the new type,
| here we are in the static context
|^
model # instance context
text name # instance variable
^|
| in EMal the instance variables are ordered, and a default
| variadic constructor is provided by the runtime.
| Every value passed to the constructor sets the instance variable
| according to the order.
|^
2024-10-16 18:07:41 -07:00
fun makeNoise ← void by block # method of Bear
2023-07-01 11:58:00 -04:00
writeLine("Growl!")
end
end
type Cat
model
text noise
new by text noise # an explicit constructor
2024-10-16 18:07:41 -07:00
me.noise ← noise # we must use me to access instance variables
2023-07-01 11:58:00 -04:00
end
2024-10-16 18:07:41 -07:00
fun makeNoise ← void by block
2023-07-01 11:58:00 -04:00
writeLine(me.noise)
end
end
type Main
2024-10-16 18:07:41 -07:00
Bear bear ← Bear("Bruno") # creating a new instance
writeLine("The bear is called ", bear.name)
2023-07-01 11:58:00 -04:00
bear.makeNoise()
Cat("Meow").makeNoise()