Hello, I'm trying to create range types with redefined operators but encountering some issues.
My program writes characters to a VGA buffer that has 80 columns and 25 lines. I figured I'd write range types for the columns and lines which I named VGACursor and VGALine respectively, and redefine the += operator so that they wrap around (go back to their low value when superior to their high value). Here is the code in question: type VGABuffer* = ptr array[0..2000, uint16] VGALine* = distinct range[0..24] VGACursor* = distinct range[0..79] FILE = object var line: VGALine = 0.VGALine cursor: VGACursor = 0.VGACursor proc `+=` (a: VGALine, b: int): VGALine = return ((a.int+b) mod 80).VGALine proc `+=` (a: VGACursor, b: int): VGACursor = if (a.int+b) > 25: line += 1 return ((a.int+b) mod 25).VGACursor var stdout* {.exportc.} : ptr FILE var stderr* {.exportc.} : ptr FILE const video_memory = cast[VGABuffer](0xB8000) proc flockfile(f: ptr FILE) {.exportc.} = discard proc funlockfile(f: ptr FILE) {.exportc.} = discard proc fflush(stream: ptr FILE): cint {.exportc.} = 0.cint proc fwrite(data: cstring, size: csize_t, nitems: csize_t, stream: ptr FILE): csize_t {.exportc.} = let backColour: byte = 0b00000000 foreColour: byte = 0b00001111 colour: byte = (backColour shl 4) or foreColour for i in 0..<size: var c = data[i] info = c.uint8 or (colour.uint16 shl 8) if c == '\n': line += 1 else: cursor += 1 video_memory[cursor.int+(line.int*80)] = info line += 1 return nitems Run And I get the error: `stdio.nim(16, 10) Error: expression 'line += 1' is of type 'VGALine' and has to be used (or discarded)` I don't know what that means, or why it appears since I've declared unused variables with no issues in the past. Could you help me understand? Also could you tell me if this is the idiomatic solution for creating wrapping range types?