From: Claudio Calvelli <c.news@w42.org.invalid>
Newsgroups: alt.lang.intercal
Subject: Program interleaving
Date: Fri, 6 Oct 2023 22:32:17 -0000 (UTC)
Organization: No thanks
Lines: 107
Message-ID: <slrnui12nh.euh.c.news@z.w42.org>

So I was thinking (sic).

To construct a two-spot number we take two one-spot numbers and
interleave their bits.  If we had the luxury of three-spot or larger
numbers we could construct them by inteleaving three or more one-spot
numbers and so on for something larger.

This is all absolutely normal, and it's not what I wanted to talk about.

If I have a number of programs and for some reason want to feed them to
the compiler all at once the obvious answer is interleaving.  This time,
at the character level rather than the bit level.

So...

1. Take (n) programs, where n is a natural number.
2. Add (or remove!) whitespace to make them all the same number of
   characters.
3. Interleave the programs.

To see what I mean by interleaving the programs, take the following
three programs:

DO READ OUT #1 PLEASE GIVE UP
DO WRITE IN .1 DO READ OUT .1 PLEASE GIVE UP
PLEASE READ OUT #2 DO GIVE UP

Add some whitespace to the first and third, and remove some from the
second so they all have the same length:

DO  READ OUT #1    PLEASE  GIVE UP
DOWRITEIN.1DOREADOUT.1PLEASEGIVEUP
PLEASE  READ  OUT  # 2  DO GIVE UP

Now interleave them by taking the first character of each ("D", "D" and
"P"), then the second ("O", "O" and "L") etc to obtain:

DDPOOL WE RARISETEAE DI  NRO.EU1ATDD O #R 1EO AU DT
O  U PT#L. E12AP SL EED AO S GEGIGIVIVEVE E UUUPPP

(To increase the already excellent legibility, I replaced a single space
with a line break).

Now save this to a file, say program.xi ("x" stands for "interleave" of
course) which will be 102 characters, and see what the compiler can do:

    sick program.xi

Note that we do not tell the compiler how many sources there are. Why
spoil its fun? However a simple calculation shows that there are only
eight possible ways to split that source:

* 1 source of 102 characters
* 2 sources of 51 characters each
* 3 sources of 34 characters each
* 6 sources of 17 characters each
* 17 sources of 6 characters each
* 34 sources of 3 characters each
* 51 sources of 2 characters each
* 102 sources of 2 characters each

The last four are automatically excluded because too short to say much
of use, so that leaves the first four; the first one doesn't look like a
program, there's a single "DO" (with s space in the middle, but still a
"DO") and no "PLEASE", which isn't quite enough to call it a program.

Well, maybe it's two sources of 51 characters each, that is, one source
contains the first, third, fifth etc character, and the other contains
the second, fourth, sixt, etc. The result is:

DPO ERRSTA I R.UAD  R1OA TO  TL 1A LEDA  EIIIEEEUUP
DOLW AIEEED NOE1TDO# E UD  UP#.E2PS E OSGGGVVV  UPP

The second line contains "DO" twice, but the first line cannot be a
program (no "DO" or "PLEASE"). Maybe it's 6 sources of 17 characters?
This gives:

D RA U 1  LAE IEU
DWIEN1OEDU.PESGVU
PES RA OT   D IEU
O EDOT#  PES GV P
ORTI.DRAOT1LAEIEP
LAE ED U #2 OGV P

A single "DO" in the fourth line, and no "PLEASE". No. Can't be a
program, so maybe it could be three sources? We get:

DO  READ OUT #1    PLEASE  GIVE UP
DOWRITEIN.1DOREADOUT.1PLEASEGIVEUP
PLEASE  READ  OUT  # 2  DO GIVE UP

Ah! That's definitely it!

The compiler generates three separate objects for these three programs,
and saves them. To run it, they will also be interleaved i.e. the
program starts with three threads, each one executing one of the three
sources. So it'll emit I II (or II I) and wait for a number; you type
a number and it emits that too.

That's it.  "Program interleaving".  I feel this will be a great way to
specify more legible threads than using multiple COME FROMs or any of
the other mechanisms to create threads.

Please interleave all replies together and post them all at once.

C

