diff options
| author | Tyge Løvset <[email protected]> | 2022-11-02 12:25:32 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-11-02 12:25:32 +0100 |
| commit | 0a9ab178aad191dc3a394e5fa8aca860da9ee9b0 (patch) | |
| tree | 02e2ab718b40b6d2b8d3a11e8d66b6e74837c35c /examples | |
| parent | a5ea027efc8b3d1e43df65dce042e945c2b48a52 (diff) | |
| download | STC-modified-0a9ab178aad191dc3a394e5fa8aca860da9ee9b0.tar.gz STC-modified-0a9ab178aad191dc3a394e5fa8aca860da9ee9b0.zip | |
Change to c_forwhile: takes start iter, not container.
Other minor updates.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/forfilter.c | 18 | ||||
| -rw-r--r-- | examples/forloops.c | 2 | ||||
| -rw-r--r-- | examples/list.c | 4 |
3 files changed, 12 insertions, 12 deletions
diff --git a/examples/forfilter.c b/examples/forfilter.c index 9079d88e..3c30b976 100644 --- a/examples/forfilter.c +++ b/examples/forfilter.c @@ -49,6 +49,7 @@ void demo1(void) /* Rust: fn main() { let vector = (1..) // Infinite range of integers + .skip_while(|x| *x != 11) // Skip initial numbers unequal 11 .filter(|x| x % 2 != 0) // Collect odd numbers .take(5) // Only take five numbers .map(|x| x * x) // Square each number @@ -60,15 +61,14 @@ fn main() { void demo2(void) { c_auto (IVec, vector) { - crange rv = crange_make(crange_MAX); - c_forfilter (x, crange, rv - , flt_isOdd(x) - && c_flt_skipwhile(x, *x.ref != 11) - , c_flt_take(x, 5)) - IVec_push(&vector, flt_square(x)); - puts("demo2:"); - c_foreach (i, IVec, vector) printf(" %d", *i.ref); + + c_forfilter (x, crange, crange_literal(INT64_MAX) + , c_flt_skipwhile(x, *x.ref != 11) + && *x.ref % 2 != 0 + , c_flt_take(x, 5)) + IVec_push(&vector, *x.ref * *x.ref); + c_foreach (x, IVec, vector) printf(" %d", *x.ref); puts(""); } } @@ -123,7 +123,7 @@ void demo5(void) #define flt_even(i) ((*i.ref & 1) == 0) #define flt_mid_decade(i) ((*i.ref % 10) != 0) puts("demo5:"); - crange r1 = crange_make(1963, crange_MAX); + crange r1 = crange_make(1963, INT32_MAX); c_forfilter (i, crange, r1 , c_flt_skip(i,15) && c_flt_skipwhile(i, flt_mid_decade(i)) diff --git a/examples/forloops.c b/examples/forloops.c index 2c604877..d016cb66 100644 --- a/examples/forloops.c +++ b/examples/forloops.c @@ -60,7 +60,7 @@ int main() printf(" (%d %d)", *_.key, *_.val);
puts("\n\nc_forwhile:");
- c_forwhile (i, IVec, vec, i.index < 3)
+ c_forwhile (i, IVec, IVec_begin(&vec), i.index < 3)
printf(" %d", *i.ref);
#define isOdd(i) (*i.ref & 1)
diff --git a/examples/list.c b/examples/list.c index e94a9f18..a538d93c 100644 --- a/examples/list.c +++ b/examples/list.c @@ -25,14 +25,14 @@ int main() { sum += *i.ref; printf("sum %f\n\n", sum); - c_forwhile (i, clist_fx, list, i.index < 10) + c_forwhile (i, clist_fx, clist_fx_begin(&list), i.index < 10) printf("%8d: %10f\n", (int)i.index, *i.ref); puts("sort"); clist_fx_sort(&list); // mergesort O(n*log n) puts("sorted"); - c_forwhile (i, clist_fx, list, i.index < 10) + c_forwhile (i, clist_fx, clist_fx_begin(&list), i.index < 10) printf("%8d: %10f\n", (int)i.index, *i.ref); puts(""); |
