I'm using autome for hotkeys, but for debugging I want to be able to check things with echo, but the compiler throws an error.
in autome Hotkey is defined as "distinct int" but when I want to display a 'Hotkey' variable I get Error: type mismatch: got <Hotkey> but expected one of:
As Termer said you can convert myVar back to an int to print it. Alternatively you can define your own proc that converts it to text:
proc `$`(a: Hotkey): string =
return "Value: " & $int(a)
The way varargs works is that it assumes each arg is a string and if not applies $(arg) to try to convert it to a string.you can borrow like so:
type Foo = distinct int
proc `$`(x: Foo): string {.borrow.}
echo (Foo 1)
also, instead of borrowing, you can use distinctBase for weird type-general nonsense:
import std / typetraits
type
Foo = distinct int
Bar = distinct float
type Distinctable = concept x
x is distinct
proc `$`[T: Distinctable](x: T): string = $T & '(' & $(T.distinctBase)(x) & ')'
echo (Foo 1)
echo (Bar 2'f)
You dont need the concept. You can just directly use the typeclass distinct
proc `$`[T: distinct](x: T): string = $T & '(' & $(T.distinctBase)(x) & ')'