The stock_symbol
is optional, it exists only for some companies, what would be proper way to declare it in Nim?
Do I have to use ref
or there's other way?
type
Company = object
name: string
stock_symbol: string
echo Company(name: "Microsoft", stock_symbol: "MSFT")
echo Company(name: "Kinetic", stock_symbol: nil)
And similar question for composite type, usually you need to know both stock exchange and the symbol
type
SymbolWithExchange = object
exchange: string
symbol: string
Company2 = object
name: string
stock_symbol: SymbolWithExchange
echo Company2(
name: "Microsoft",
stock_symbol: SymbolWithExchange("NYSE", "MSFT")
)
echo Company2(name: "Kinetic", stock_symbol: nil)