Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Vulcans worship peace above all. -- McCoy, "Return to Tomorrow", stardate 4768.3


devel / comp.lang.awk / Re: cppawk: parallel/product iteration syntax.

SubjectAuthor
* cppawk: parallel/product iteration syntax.Kaz Kylheku
`* Re: cppawk: parallel/product iteration syntax.Kaz Kylheku
 `- Re: cppawk: parallel/product iteration syntax.Kaz Kylheku

1
cppawk: parallel/product iteration syntax.

<20220330103602.734@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1184&group=comp.lang.awk#1184

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: cppawk: parallel/product iteration syntax.
Date: Wed, 30 Mar 2022 19:18:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <20220330103602.734@kylheku.com>
Injection-Date: Wed, 30 Mar 2022 19:18:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="feba35e252216a647f47d8c5f6a75883";
logging-data="5984"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/J9eBjLLv4SyISKMoBUJOTJnAgM1fdchk="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:DA4QTu35eXZDwZEJkJ9Fbk+srZQ=
 by: Kaz Kylheku - Wed, 30 Mar 2022 19:18 UTC

I didn't suspect C99 preprocessing would be up to this, but, lo and behold:

../cppawk '
#include <loop.h>

BEGIN {
$0 = "o p q r s t u v w x y z" # set fields

split("! @ # $ % ^ & * ( )", arr) # init array

loop (range(i, 1, 10),
from(x, 5),
from_step(y, 100, 5),
str(j, ch, "abcdefghijklmn"),
fields(f),
keys(k, arr))
{
print i, x, y, ch, f, k, arr[k]
}
}'
1 5 100 a o 1 !
2 6 105 a p 2 @
3 7 110 b q 3 #
4 8 115 c r 4 $
5 9 120 d s 5 %
6 10 125 e t 6 ^
7 11 130 f u 7 &
8 12 135 g v 8 *
9 13 140 h w 9 (
10 14 145 i x 10 )

Cross-producing loop:

$ ./cppawk '
#include <loop.h>

BEGIN {
$0 = "a b c" # set fields

split("X Y", arr) # init array

loop_cross (fields(f),
keys(k, arr),
range(i, 1, 3))
{
print f, arr[k], i
}
}'
a X 1
a X 2
a X 3
a Y 1
a Y 2
a Y 3
b X 1
b X 2
b X 3
b Y 1
b Y 2
b Y 3
c X 1
c X 2
c X 3
c Y 1
c Y 2
c Y 3

The loop clauses are user-definable, and easily so; I'm going to have
documentation on exactly how to do that.

For instance, the clause range(index, from, to) is entirely defined in
these three simple lines of code in <loop.h>, which are entirely
isolated from the complexity of loop and loop_cross:

#define __init_range(idx, from, to) (idx = (from))
#define __test_range(idx, from, to) (idx <= (to))
#define __step_range(idx, from, to) (idx++)

Re: cppawk: parallel/product iteration syntax.

<20220330140913.51@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1185&group=comp.lang.awk#1185

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: cppawk: parallel/product iteration syntax.
Date: Wed, 30 Mar 2022 21:38:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 95
Message-ID: <20220330140913.51@kylheku.com>
References: <20220330103602.734@kylheku.com>
Injection-Date: Wed, 30 Mar 2022 21:38:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="feba35e252216a647f47d8c5f6a75883";
logging-data="5185"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/+v7WdbZbfoRZR+bkScmVaLMl6E86L5cs="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:33qNfM5r8h3uoNje5q1smQaPhBA=
 by: Kaz Kylheku - Wed, 30 Mar 2022 21:38 UTC

On 2022-03-30, Kaz Kylheku <480-992-1380@kylheku.com> wrote:
> The loop clauses are user-definable, and easily so; I'm going to have
> documentation on exactly how to do that.
>
> For instance, the clause range(index, from, to) is entirely defined in
> these three simple lines of code in <loop.h>, which are entirely
> isolated from the complexity of loop and loop_cross:
>
> #define __init_range(idx, from, to) (idx = (from))
> #define __test_range(idx, from, to) (idx <= (to))
> #define __step_range(idx, from, to) (idx++)

E.g. let's make a clause "sfixes"
that loops over string suffixes, e.g "abc" "bc" "c"

../cppawk '
#include <loop.h>

// user-defined "sfixes" loop clause

#define __init_sfixes(idx, ch, str) (idx = 1)
#define __test_sfixes(idx, ch, str) (idx <= length(str) && \
((ch = substr(str, idx)) || 1))
#define __step_sfixes(idx, ch, str) (idx++)

// use it

BEGIN {
loop (sfixes(i, sf, "abcd"))
print i, sf
}'
1 abcd
2 bcd
3 cd
4 d

Or how about controling the length of the string slices.

No, how about completely controlling the string slice and just binding
the variable:

No, let's first make a general clause "let" to set a arbitrary variable
on each iteration of the loop.

../cppawk '
#include <loop.h>

// user-defined "let" loop clause

#define __init_let(var, expr) 0
#define __test_let(var, expr) ((var = (expr)) || 1)
#define __step_let(var, expr) 0

BEGIN {
loop (range(i, 1, 10),
range_step(j, 1, 10, 2),
let(ch, substr("abcdefghijklmn", i, j)))
{
print i, j, ch
}
} '
1 1 a
2 3 bcd
3 5 cdefg
4 7 defghij
5 9 efghijklm

How about general "first_then_until" stepping clause.

../cppawk '
#include <loop.h>

// user-defined "first_then_until" loop clause

#define __init_first_then_until(var, first, then, until) (var = (first))
#define __test_first_then_until(var, first, then, until) (!(until))
#define __step_first_then_until(var, first, then, until) (var = (then))

BEGIN {
loop (first_then_until(i, 1, i * 2, i >= 60),
first_then_until(s, "x", s s, 0))
{
print i, s
}
} '
1 x
2 xx
4 xxxx
8 xxxxxxxx
16 xxxxxxxxxxxxxxxx
32 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Re: cppawk: parallel/product iteration syntax.

<20220330160349.815@kylheku.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1186&group=comp.lang.awk#1186

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-1380@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.awk
Subject: Re: cppawk: parallel/product iteration syntax.
Date: Wed, 30 Mar 2022 23:19:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 67
Message-ID: <20220330160349.815@kylheku.com>
References: <20220330103602.734@kylheku.com> <20220330140913.51@kylheku.com>
Injection-Date: Wed, 30 Mar 2022 23:19:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f8be93b4555e8b406f842eb174eb9672";
logging-data="8183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/qCIGRD0fZE+x9rbaWKdhy3myomX8GAWM="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:omhWSWI5T91Gz+Ch5cHetuLz9Ak=
 by: Kaz Kylheku - Wed, 30 Mar 2022 23:19 UTC

On 2022-03-30, Kaz Kylheku <480-992-1380@kylheku.com> wrote:
> BEGIN {
> loop (first_then_until(i, 1, i * 2, i >= 60),
> first_then_until(s, "x", s s, 0))
> {
> print i, s
> }
> }
> '
> 1 x
> 2 xx
> 4 xxxx
> 8 xxxxxxxx
> 16 xxxxxxxxxxxxxxxx
> 32 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

List collection. (Poor implementation: the framework will have to
adjusted to make it possible in a better way):

../cppawk '
#include <loop.h>
#include <cons.h> // Lisp-inspired data structure framework.

#define __init_collect(tmp, var, expr) (tmp = list_begin())
#define __test_collect(tmp, var, expr) ((tmp = list_add(tmp, expr)) && \
(var = list_end(tmp))) || 1
#define __step_collect(tmp, var, expr) 1

BEGIN {
loop (range(i, 1, 10),
collect(tmp, lst, i))
{
print i
}

print sexp(lst)

dolist (i, lst)
print i, i * 10
} '
1 2
3 4
5 6
7 8
9 10
(1 2 3 4 5 6 7 8 9 10)
1 10
2 20
3 30
4 40
5 50
6 60
7 70
8 80
9 90
10 100

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor