From 786098e100860304fa90cd6560af0a01a1e9f48d Mon Sep 17 00:00:00 2001 From: Bob Tolbert Date: Tue, 4 Feb 2025 10:57:37 -0600 Subject: [PATCH 1/2] add examples for eachp --- examples/eachp.janet | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 examples/eachp.janet diff --git a/examples/eachp.janet b/examples/eachp.janet new file mode 100644 index 00000000..a4ec9287 --- /dev/null +++ b/examples/eachp.janet @@ -0,0 +1,12 @@ +# keys for tuple/array are 0-based index +# prints 0->1 1->2 2->3 3->4 4->5 +(eachp [i x] [1 2 3 4 5] (prin i "->" x " ")) + +(eachp [i x] @[1 2 3 4 5] (prin i "->" x " ")) + +# key, value from table/struct, but maybe not in order +# prints :b -> 2 :a -> 1 +(eachp [k v] {:a 1 :b 2} (prinf "%v -> %v " k v)) + +# prints :foo -> "A" :bar -> "B" +(eachp [k v] @{:foo "A" :bar "B"} (prinf "%v -> %v " k v)) From 7544e5cda5cb9bf8556a61046ed44b46d702b118 Mon Sep 17 00:00:00 2001 From: Bob Tolbert Date: Wed, 5 Feb 2025 10:01:37 -0600 Subject: [PATCH 2/2] tweaks examples to match more consistent style --- examples/eachp.janet | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/eachp.janet b/examples/eachp.janet index a4ec9287..96535af9 100644 --- a/examples/eachp.janet +++ b/examples/eachp.janet @@ -1,12 +1,13 @@ # keys for tuple/array are 0-based index -# prints 0->1 1->2 2->3 3->4 4->5 -(eachp [i x] [1 2 3 4 5] (prin i "->" x " ")) +# prints 0->:a 1->:b 2->:c 3->:d 4->:e +(eachp [i x] [:a :b :c :d :e] (prinf "%v->%v " i x)) # -> nil -(eachp [i x] @[1 2 3 4 5] (prin i "->" x " ")) +# prints 0->"a" 1->"b" 2->"c" 3->"d" 4->"e" +(eachp [i x] @["a" "b" "c" "d" "e"] (prinf "%v->%v " i x)) # -> nil -# key, value from table/struct, but maybe not in order +# key, value from table/struct in an unspecified order # prints :b -> 2 :a -> 1 -(eachp [k v] {:a 1 :b 2} (prinf "%v -> %v " k v)) +(eachp [k v] {:a 1 :b 2} (prinf "%v -> %v " k v)) # -> nil # prints :foo -> "A" :bar -> "B" -(eachp [k v] @{:foo "A" :bar "B"} (prinf "%v -> %v " k v)) +(eachp [k v] @{:foo "A" :bar "B"} (prinf "%v -> %v " k v)) # -> nil