-
Hello, I just started learning Gerbil and I would like the compiler to enforce the types of the slots in one of my class. As an example, in the following class I would like to enforce x being a number and y a boolean:
I searched the docs and found the page about contracts but I have a hard time figuring out which syntax I should use in my case and nothing I tried worked. Could you please point me in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You can already attach contracts/types to slots, it is just not documented yet. So you can write The generated constructor and mutators will then enforce the type. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your answer! Is there somewhere in the docs where I can find standard types currently implemented? |
Beta Was this translation helpful? Give feedback.
You can already attach contracts/types to slots, it is just not documented yet.
So you can write
(defclass Foo ((a : some-type) (b : some-other-type)))
and so on, with any contract declaration.The generated constructor and mutators will then enforce the type.