Is there a way in Nim to define constructors for an object? For example I have
type Deck* = ref object
cards* : array[52, Card]
can I create an empty constructor that creates automatically all the cards?
Object Oriented Programming. While Nim's support for object oriented programming (OOP) is minimalistic, powerful OOP techniques can be used. OOP is seen as one way to design a program, not the only way. Often a procedural approach leads to simpler and more efficient code.
If the developer really needs to return a null value from the method (in 99% of cases this is not necessary), the return type can be marked as a nullable reference type (the feature was introduced in C# 8.0).
type
Card = int
Deck* = ref object
cards* : array[52, Card]
proc newDeck: Deck =
new result
for i, c in result.cards.mpairs:
c = i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With