summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/forloops.c
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-04-12 15:55:33 -0400
committerrealtradam <[email protected]>2023-04-12 15:55:33 -0400
commit0841165881871ee01b782129be681209aeed2423 (patch)
tree8a76b61dcaab381b6b42305201ae8b6259f6b6c0 /misc/examples/forloops.c
parent554f3e8acf7855b5d6a90cc68cefb7445460b03c (diff)
parent0516aa3ae823ed9a22b2c5f776948c8447c32c31 (diff)
downloadSTC-modified-0841165881871ee01b782129be681209aeed2423.tar.gz
STC-modified-0841165881871ee01b782129be681209aeed2423.zip
Merge branch 'master' into modified
Diffstat (limited to 'misc/examples/forloops.c')
-rw-r--r--misc/examples/forloops.c74
1 files changed, 31 insertions, 43 deletions
diff --git a/misc/examples/forloops.c b/misc/examples/forloops.c
index 707e8285..1fc00614 100644
--- a/misc/examples/forloops.c
+++ b/misc/examples/forloops.c
@@ -25,7 +25,6 @@ int main()
c_forrange (i, 30, 90, 2) printf(" %lld", i);
-
puts("\n\nc_forlist:");
c_forlist (i, int, {12, 23, 453, 65, 676})
printf(" %d", *i.ref);
@@ -35,47 +34,36 @@ int main()
printf(" %s", *i.ref);
puts("");
- c_forlist (i, const char*, {"12", "23", "453", "65", "676"})
- printf(" %s", i.data[i.size - 1 - i.index]);
-
-
- c_auto (IVec, vec)
- c_auto (IMap, map)
- {
- c_forlist (i, int, {12, 23, 453, 65, 113, 215, 676, 34, 67, 20, 27, 66, 189, 45, 280, 199})
- IVec_push(&vec, *i.ref);
-
- c_forlist (i, IMap_value, {{12, 23}, {453, 65}, {676, 123}, {34, 67}})
- IMap_push(&map, *i.ref);
-
- puts("\n\nc_foreach:");
- c_foreach (i, IVec, vec)
- printf(" %d", *i.ref);
- puts("");
-
- c_foreach (i, IMap, map)
- printf(" (%d %d)", i.ref->first, i.ref->second);
-
- puts("\n\nc_forpair:");
- c_forpair (key, val, IMap, map)
- printf(" (%d %d)", *_.key, *_.val);
-
- puts("\n\nc_forwhile:");
- c_forwhile (i, IVec, IVec_begin(&vec), i.index < 3)
- printf(" %d", *i.ref);
-
- #define isOdd(i) (*i.ref & 1)
-
- puts("\n\nc_forfilter:");
- c_forfilter (i, IVec, vec
- , c_flt_skipwhile(i, *i.ref != 65)
- && c_flt_takewhile(i, *i.ref != 280)
- && c_flt_skipwhile(i, isOdd(i))
- && isOdd(i)
- && c_flt_skip(i, 2)
- && c_flt_take(i, 2))
- printf(" %d", *i.ref);
- puts("");
- // 189
+ IVec vec = c_make(IVec, {12, 23, 453, 65, 113, 215, 676, 34, 67, 20, 27, 66, 189, 45, 280, 199});
+ IMap map = c_make(IMap, {{12, 23}, {453, 65}, {676, 123}, {34, 67}});
+
+ puts("\n\nc_foreach:");
+ c_foreach (i, IVec, vec)
+ printf(" %d", *i.ref);
+
+ puts("\n\nc_foreach_r: reverse");
+ c_foreach_rv (i, IVec, vec)
+ printf(" %d", *i.ref);
+
+ puts("\n\nc_foreach in map:");
+ c_foreach (i, IMap, map)
+ printf(" (%d %d)", i.ref->first, i.ref->second);
+
+ puts("\n\nc_forpair:");
+ c_forpair (key, val, IMap, map)
+ printf(" (%d %d)", *_.key, *_.val);
+
+ #define isOdd(i) (*i.ref & 1)
+
+ puts("\n\nc_forfilter:");
+ c_forfilter (i, IVec, vec,
+ isOdd(i) &&
+ c_flt_skip(i, 4) &&
+ c_flt_take(i, 4)
+ ){
+ printf(" %d", *i.ref);
}
+
+ IVec_drop(&vec);
+ IMap_drop(&map);
}