Article View: comp.lang.tcl
Article #84Re: Announce bitarray 1.0 - packed integer arrays for Tcl 9 (C extension)
From: et99
Date: Fri, 23 Oct 2026 11:15
Date: Fri, 23 Oct 2026 11:15
61 lines
4522 bytes
4522 bytes
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 <et99@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'
Technical Details
Message-ID:
<11bffkm$1ntq9$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11bb56j$8k4k$1@dont-email.me> <1792660578-1108@newsgrouper.org> <11bf5sa$1ju6e$1@dont-email.me> <ygacxt0dchk.fsf@akutech.de>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: et99 <et99@rocketship1.me> Newsgroups: comp.lang.tcl Subject: Re: Announce bitarray 1.0 - packed integer arrays for Tcl 9 (C extension) Date: Fri, 23 Oct 2026 04:15:34 -0700 Organization: A noiseless patient Spider Lines: 61 Message-ID: <11bffkm$1ntq9$1@dont-email.me> References: <11bb56j$8k4k$1@dont-email.me> <1792660578-1108@newsgrouper.org> <11bf5sa$1ju6e$1@dont-email.me> <ygacxt0dchk.fsf@akutech.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 23 Oct 2026 11:15:34 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1832777"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Upvj0a6xcA8v7Qx9hR3jc"; posting-host="69e81acc20d4d43c58ecbffdbd3be501" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:vWVgfDFZbtoPpnNvvt8OlKeEL7c= sha256:f6mkjAnf+oTT+ZWF39K9EmRBdW2jQVyo4rDHbpyVSvk= sha1:ryEW64JPSu0g/wpHD1KUF+SZYMw= sha256:icCjDoNlrNKGNdtXUBOqVzaVnY2+NiOC/a41Rg8hjzM= In-Reply-To: <ygacxt0dchk.fsf@akutech.de> Content-Language: en-US