[net.bizarre] More Bizzare Code

dimitrov@csd2.UUCP (Isaac Dimitrovsky) (08/23/85)

[]
Some more bizzare code:

k := ord(odd(i) and odd(j));

This is UCSD Pascal (IBM PC version)'s brilliant way of seamlessly
adding the bitwise and operation to Pascal. The above line assigns
the bitwise and of i and j to k. The way this works is as follows.
Booleans are implemented as integer-size quantities. The test for
whether a Boolean-type object is true, however, only involves the
low bit of the object, which is set for true and clear for false;
the other bits are ignored. *However*, a boolean and operation in
fact does a bitwise and of its operands even though only the low
bits are significant. Finally, because of the above, the odd
predicate can simply be a no-op at the machine level, i.e. odd(i)
can simply return i since the low bit of i will be set iff i is odd.
The ord function is also a no-op, as usual. So what happens for the
expression above is: odd(i), odd(j) return i, j unchanged;
and does a bitwise and of the boolean but in fact integer operands;
and ord returns the result of this as an integer. Truly an example
to us all of how to extend a language in a clear and machine
independent way.

loop:	store 23 in x
	if x<>58 goto loop

I had to write something very much like the above code on the Atari 800.
You see, x was a memory-mapped rom i/o location or something, and when
you stored to it that caused one kind of side effect, and when you read
from it that actually read some other status that was sort of related
to the first side effect but not exactly. Something like that, anyway.
It's all getting fuzzy around the edges ...

Isaac Dimitrovsky
allegra!cmcl2!csd2!dimitrov   (l in cmcl2 is letter l not number 1)
251 Mercer Street, New York NY 10012

... Hernandez steps in to face ... Orl ... HERchiiiser ... and it's a liiine
driive, deeeeep to the gap in left center ...	- Bob Murphy, Voice of the Mets