Hi there, I'm very new to Nim.
I have some code:
type
LitKind* = enum
NumLit,
StrLit,
NilLit,
BoolLit
LitType* = object
case litKind*: LitKind
of NumLit: n*: float64
of StrLit: s*: string
of BoolLit: b*: bool
of NilLit: discard
Expr = ref object of RootObj
Literal = ref object of Expr
value: LitType
BinOp = ref object of Expr
left, right: Expr
op: string
var left = Literal(value: LitType(litKind: NumLit, n: 5.0))
var right = Literal(value: LitType(litKind: NumLit, n: 6.0))
var add = BinOp(left: left, op: "+", right: left)
echo add[]
echo add[].left
Run
the first echo statement works, although I'm not super sure why I need to add
the square brackets on add.
But, the second echo statement does not work. How can I access add.left?