proc last[T](ll: seq[T]): var T =
return ll[high(ll)]
if last(formula)["state"] == c_empty:
Errors:
main.nim(118, 12) Info: template/generic instantiation from here main.nim(12, 12) Error: expression has no address
What the compiler wants?
import tables
type
Tformula_elt = Table[string, int]
proc empty_state(): var Tformula_elt =
return toTable({"size": 0, "minus_count": 0, "state": 0})
temp.nim(8, 17) Error: expression has no address
I don't think var is what you want here, and probably not in the previous code either. If you want the ability to mutate the returned variable then all you have to do is var x = empty_state() instead of let x = empty_state()
EDIT: SO answer updated
import tables
type
Tformula_elt = Table[string, int]
proc last[T](ll: var seq[T]): var T =
return ll[high(ll)]
proc empty_state(): Tformula_elt =
return toTable({"size": 0, "minus_count": 0, "state": 0})
proc symm_region_formulas(n: int): void =
var formula = @[empty_state()]
var d = addr(last(formula))
d[]["size"] += 1
temp.nim(16, 15) Error: type mismatch: got (int, int literal(1)) but expected one of: system.+=(x: var T, y: T) system.+=(x: var T, y: T)
proc foo: int = 8
foo() = 3 # doesn't compile
var f = foo()
f = 3 # compiles
So clearly the var/let declaration creates the location, not the call to foo.