Hopefully simple Nim syntax question

2022-04-14 Thread ynfle
The reason is because `var` means it will be modified. If it's passed in like that how are you supposed to "retrieve" the modification

Hopefully simple Nim syntax question

2022-04-14 Thread DMisener
Thanks… mystery solved… As to why the compiler doesn’t realize it is being passed into a proc requiring a _var_ and accommodating is interesting.

Hopefully simple Nim syntax question

2022-04-14 Thread ynfle
See `sugar.dup`

Hopefully simple Nim syntax question

2022-04-14 Thread PMunch
@aEverr is correct. The actual error here is that `toHeapQueue` requires a variable (something it can modify, so a `let` won't work, only `var`). Unfortunately values that you only pass in to a procedure aren't considered variable by the Nim compiler for some reason. So you have to first assign

Hopefully simple Nim syntax question

2022-04-14 Thread aEverr
in the first lastStoneWeight, `proc lastStoneWeight(stones: var Stones): int`, it requires a var. `var stones = weights.mapIt(Stone(weight: it)).toHeapQueue` makes a var or a variable to a mutable value, okay, and you pass it. `result = lastStoneWeight(stones)` but here,

Hopefully simple Nim syntax question

2022-04-14 Thread DMisener
Probably very simplebut stumps me :-( Any explanation would be appreciated... * * * Why is line 25: lastStoneWeight(weights.mapIt(Stone(weight: it)).toHeapQueue) Run not equivalent to commented out lines at 23-24: var stones =