1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-21 18:57:41 +00:00

Add eachk and eachp.

These should make iterating over datastructures easier
without needing the loop macro.
This commit is contained in:
Calvin Rose
2020-01-18 18:44:41 -06:00
parent f4077b678a
commit 064475cb8d
2 changed files with 17 additions and 3 deletions

View File

@@ -420,10 +420,20 @@
[i start stop & body]
(for-template i start stop 1 < + body))
(defmacro eachk
"loop over each key in ds. returns nil."
[x ds & body]
(keys-template x ds false body))
(defmacro eachp
"Loop over each (key, value) pair in ds. Returns nil."
[x ds & body]
(keys-template x ds true body))
(defmacro each
"Loop over each value in ind. Returns nil."
[x ind & body]
(each-template x ind body))
"Loop over each value in ds. Returns nil."
[x ds & body]
(each-template x ds body))
(defmacro loop
"A general purpose loop macro. This macro is similar to the Common Lisp