Hello all,
A newbie here. I have been learning Nim using the online tutorials and is
thoroughly enjoying Nim . I have completed the part 1 and have advanced to Part
2 of the tutorial. Have a question regarding the setter methods discussed in
the 'Properties' section of the tutorial. Can you please help.
The code looks like this. It appears like **s.host = 34** is not calling the
setter proc. At the same time , s.`host=` 34 calls the setter proc.
Also is there a facility in Nim to mark class variables as Private/Public?
Thanks in advance.
type
Socket = ref object of RootObj
host: int # cannot be accessed from the outside of the module due to
missing star
proc `host=`(s: var Socket, value: int) {.inline.} =
## setter of host address
s.host = value
proc host(s: Socket): int {.inline.} =
## getter of host address
echo "inside the getter host method"
s.host
var s: Socket
new s
s.host = 34 # => does not call the host= proc. "inside the getter method"
string is not printed
s.`host=` 34 # => works as expected. host= proc is called.