Ken Ian Gordon writes on Tuesday, April 9:

Quote:

> NB. basic bit pack used on flags and in other to compress bits

(I rudely rearranged the order of presentation in the original

article to make my points.)

The "pbit" verb can be stated more succinctly by exploiting

negative infixes: (-n)f\x applies f to non-overlapping moving

"windows" of size n in items of x. The window size here would

be 31, and the verb the identity [ . Thus:

1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1 1 1

This version of "pbit" does not give the same results as the

original "pbit", but the differences are only in the "slop-over"

in the final 31 bits, and unpacks to the same result.

Quote:

> NB. Type 1 - pack empty ch or zero value fields

I admit to a bias against constructs of the form (f g)~ or (f~ g)~ ,

because I get confused after one or two commutes keeping track of

which argument is which. Thus I myself would favor:

The verb "spread", taking a boolean left argument b and a right

argument x, computes (-.b) expand x in a way much superior

to my own:

(c*+/\c=.-.b) { (0{1{.0$x) , x

When I devised this solution (in 1987), I had a bias against

because in most APL implementations the second grade (let alone

the first) was slower than some linear-time circumlocutions.

It was Arthur Whitney who first pointed out to me that with the

improvements to /: (and \:) there is no longer any reason to

void the simpler expressions.

Finally, it may be more direct to retain the original boolean

mask rather than its negation, whence the decoding function can

be exactly "expand". (My troubles with negation are similar to

my troubles with commute.) Thus:

Quote:

> NB. Type special - pack sparse arrays of numbers

As far as I can tell, these functions are equivalent to

That is, to pack, retain the shape, then apply the vector case

to the ravelled argument; to unpack, reshape the unpacked vector.

Quote:

> NB. utilities

> ntoc =: ({&a.)

> cton =: a.&i.

By the way, the interpreter "knows" that "ntoc" and "cton"

are inverses. Thus:

{&a. ^: _1

a.&i.

a.&i. ^: _1

{&a. :.(a.&i.)