I've defined a custom type in my nim script, here's the definition:
type
Terminal = tuple
name: string
terminalType: TerminalType # enum defined elsewhere in the program
parentComponent: ref Component # type defined elsewhere in the program
However when I use .add() to append a Terminal to a seq[Terminal] I get a type mismatch error. How do I fix this? Tried to reconstruct it using your playground but it doesn't produce the same error so here's the exact code. Sorry if it's a bit unreadable :/
Works using intermediate variables (and one var in proc definition):
It's a subtle bug, but essentially your object isn't mutable, so the sequence isn't mutable. The type error is because it's seq[Terminal] and add requires a var seq[Terminal]. Replacing schematicConnect with this works:
proc schematicConnect(schematic: var Schematic, terminal: Terminal, node: Terminal): bool =
for adjacencyList in schematic.mitems:
if adjacencyList.terminal == terminal:
adjacencyList.connections.add(node)
for adjacencyList in schematic.mitems:
if adjacencyList.terminal == node:
adjacencyList.connections.add(terminal)