Hi Ralf:
Think of the bitwise operators as AND-ing two huge words made of all the bits, while land and the relational operators look at each element as a number. Here's a claude example:
a = 5 0 2 7 ;# 0101 0000 0010 0111
b = 2 3 0 7 ;# 0010 0011 0000 0111
bitarray op $a and $b ;# 0 0 0 7 bit by bit: 5 and 2 share no bits
bitarray op $a land $b ;# 1 0 0 1 1 where both elements are non-zero
Bitwise: both arrays need the same width and the same sign. An 8-bit and a 16-bit array is an error, and so is 8 with -8. The reason is the "one huge word" picture. The bits only line up element for element when the elements are the same size, and a signed and an unsigned array don't mean the same thing by the same bits.
Logical and relational: the widths and signs may differ. These operators look at each element as a number (or as zero versus non-zero), so an 8-bit element can be compared with a 32-bit one. For example, -8 against 16 is fine.
Here -8 means '-width -8' which means 8-bit signed, while 16 means '-width 16' is 16-bit unsigned (it was a cheap trick to save needing -unsigned or some such).
As for X, it is not a typo.
In bitarray op X = X and $Z the first X, after the "=", is written without a dollar sign on purpose. A bare variable name means "this variable itself", not the contents: so the array it holds is changed where it is, with no new array allocated (like lset or lappend, which also take a variable name). With the dollar sign,
bitarray op X = $X and $Z
you get the same result, but a new array is built and stored in X. The old array is freed as soon as X is given the new one, unless another variable still shares it. In that case it is freed when the last holder goes.
However,
bitarray op V = X and $Z
is an error, since both sides of the equal sign must be the same bare variable. This catches missing $ and misspelled names. The error you will see is "expected a bitarray or an integer of at most 64 bits but got X", because a bare name that is not the destination is not treated as an array. Anyway that was the idea. I think it will take some getting used to.
Thanks for your interest,
Eric
On 10/23/2026 1:53 AM, Ralf Fassel wrote:
> * et99 <et…@rocketship1.me>
> | The answer to your question is that they aren't mnemonics, they are
> | the operator words of bitarray op. 'land' is a logical 'and' along
> | with two other logicals: 'lor' and 'lnot'.
>
> Being curious: 'and' for two bitarrays seems logical (do 'and' for every
> bit in each array) , but what is 'land' in this respect? Does this use
> the whole array (1 if any bit is on, 0 else) and do the "logical and" for
> these two?
>
> | and the bitarray times, 7.9 microseconds for 1-bit arrays and 60 for
> | 8-bit ones, are for the single command:
>>
> | bitarray op X = X and $Z ;# updates X in place: X = X and Z
>
> I would have expected
>
> bitarray op X = _$_X and $Z
>
> ("_" for emphasis) - is this a typo in the posting or a misunderstanding
> on my side?
>
> Interesting project!
> R'