I was practicing on the Io language. Finding sources is so hard. As you know there is no class in the Io language. But we can create our classes with our needings. Anyway, let's say I want to be able to run this and create an Animal class.
Animal := Class new("Animal",
withConstructor(nameParam,
name = nameParam
)
withInstanceAttribute("name", "")
withInstanceAttribute("foodItemsEaten", 0)
withStaticAttribute("allFoodItemsEaten", 0)
withMethod("feed", howMuchFood,
foodItemsEaten = foodItemsEaten + howMuchFood
class allFoodItemsEaten = allFoodItemsEaten + howMuchFood
"#{name} has just eaten #{howMuchFood} food items." interpolate println
)
withMethod("feedSummary",
"So far #{foodItemsEaten} food items eaten by #{name} and #{class allFoodItemsEaten} in total by all dogs." interpolate println
)
)
So I have this class structure:
Class := Object clone
Class new := method(name, // Meta-class constructor
cls := Class clone
cls __name := name // Name of the class
cls __instanceProto := Object clone // Prototype of instances - hold instance field along with their initial values
cls __instanceProto class := cls
call argAt(1) doInContext(cls)
cls
)
I'm trying to add withConstructor method for example, but I can't even read the parameters.
Class withConstructor := method(nameParam
self
)
I just couldn't handle it, even the constructor. It says "Class doesn't respond nameParam". The syntax is easy, but I guess I still didn't figure out the structure of the language. Any idea, similar sources, or someone who can explain it?