Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nim how to define constructors?

Tags:

oop

nim-lang

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?

like image 818
Mikedev Avatar asked Oct 17 '17 21:10

Mikedev


People also ask

Is Nim an OOP?

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.

Can C# new return null?

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).


1 Answers

type
  Card = int
  Deck* = ref object
    cards* : array[52, Card]

proc newDeck: Deck =
  new result
  for i, c in result.cards.mpairs:
    c = i
like image 60
def- Avatar answered Oct 04 '22 03:10

def-