munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.79k stars 1.03k forks source link

Confusing sentence about intializer's arity in 12.6 #940

Closed mhmdk closed 3 years ago

mhmdk commented 3 years ago

Hello, in 12.6 constructors-and-initializers, under the implementation of LoxClass::arity(), there is a sentence that says: "We don’t require a class to define an initializer, though, as a convenience". I guess it should be ""We don’t require an initializer to define a class, though, as a convenience".

Thanks

jcgoble3 commented 3 years ago

Seems right to me. A class defines methods, one of which can be an initializer. But the class does not have to define an initializer, in which case the constructor has an implicit arity of zero (as there's nothing to pass any arguments to).

It would be weird for an initializer to define a class inside of it.

mhmdk commented 3 years ago

yes, I misinterpreted the "we require" part. Thanks for clarification. I am closing the issue