please who can explain this code

2023-11-18 Thread jrfondren
echo type(sparky) # Animal echo type(sparky[]) # Animal:ObjectType Run Since `Animal` is defined as a `ref object`, you can deference it get the underlying `object`, and `object` types have have default printers in Nim.

please who can explain this code

2023-11-18 Thread jrfondren
1. `echo sparky` doesn't work as you haven't defined the appropriate `$` for it. 2. `sparky.$()` looks like the use of a dot-like operator named `.$` 3. `$sparky` doesn't work as you've only defined a `$` that takes two parameters Apart from that, it's easy to understand, right? If you w

please who can explain this code

2023-11-18 Thread treeform
I fixed your program (with beef's help) so that it fits on one line: type Animal = tuple[name:string;age:int];let speak=(proc(self:var Animal,msg:string)=echo self.name&" says:"&msg);let setName=(proc(self:var Animal,name:string)=self.name=name);let incAge=(proc(self:var Animal)=se

please who can explain this code

2023-11-18 Thread Isofruit
Turns out the formatters appear to not like code-blocks without _any_ other .text

please who can explain this code

2023-11-18 Thread isaiah
`type Animal = ref object name: string age: int proc speak(self: Animal, msg: string) = echo self.name & " says:" & msg proc setName(self: Animal, name:string) = self.name = name proc incAge(self: Animal) = self.age += 1 proc `$`(x:Animal ): string= $x.name & " is " & $x.age & " years old" var s

please who can explain this code

2023-11-18 Thread isaiah
thanks for the quick reply, i really do not know how to format the code using rst. after going through the nim manual i was able to fix it.

please who can explain this code

2023-11-18 Thread isaiah
`type Animal = ref object name: string age: int proc speak(self: Animal, msg: string) = echo self.name & " says:" & msg proc setName(self: Animal, name:string) = self.name = name proc incAge(self: Animal) = self.age += 1 proc `$`(x, y:Animal ): string= $x.name & " is " & $y.age.int & " old" var

please who can explain this code

2023-11-18 Thread Isofruit
I'd like to ask you to at least format this instead of forcing it into a single line. It's intensely difficult to read in this format. Ideally just use three backticks aka: ```nim ```