janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.43k stars 221 forks source link

Update `each` keys before body #1258

Closed primo-ppcg closed 1 year ago

primo-ppcg commented 1 year ago

Fixes #1220

Changes each-template to update the iteration key after bindings and before the body, rather than after the body. As the iteration key is not exposed to the body, I believe this has no consequence, other than to resolve the linked issue.

(let [t @{1 true 2 true 3 true 4 true}]
  (eachk k t
    (when (even? k)
      (put t k nil)))
  t)

master:

@{1 true 3 true 4 true}

branch:

@{1 true 3 true}
sogaiu commented 1 year ago

Tried the changes out and ran some projects' tests (including spork's) with no issues :+1:


Finally used jpm's --janet option:

jpm --local --janet=$HOME/src/janet.primo-ppcg/build/janet test