1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-24 06:06:52 +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

@ -20,6 +20,10 @@ All notable changes to this project will be documented in this file.
- Add `when-with`
- Add `if-with`
- Add completion to the default repl based on currently defined bindings.
- Add `eachk`
- Add `eachp`
- Improve functionality of the `next` function. `next` now works on many different
types, not just tables and structs. This allows for more generic data processing.
- Fix thread module issue where sometimes decoding a message failed.
- Fix segfault regression when macros are called with bad arity.

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