In the early 1970s, I had university a co-op job at a place where one of the main languages used was like a glorified calculator.
It provided two stacks, and all variables and operators were a single character.
Depending upon context each letter could be overloaded and interpreted as a scalar (x+2
), a vector (x@2
), a function (x:2
), or whatever.
(I'm guessing about the syntax; it could have been quite different.)
I'm pretty sure it was either in-house, or provided by some external company that wrote and maintained it for them.
The interesting thing for me is that all arrays were powers of 2 in length.
I no longer remember the declaration syntax, but I imagine that each array was stored with an appropriate bit mask, so that x@y
was a reference to address x+(y&mask)
.
All arrays were thus circular.
This meant that there was no possibility of having indexes out of range.
It also meant that x@-2
would naturally be the second from the end of the array, without requiring any different processing than for x@2
.
(Remember, this was at a time when an extra instruction or two was considered expensive.)
There were times when this behaviour came in handy (though I really can't remember any specific examples).
I'm wondering if any "real" languages ever provided arrays like this.
malloc()
, perhaps the original BSD, where the allocated blocks were a power of 2, but the first 4 bytes were used to store the size of the block for use byfree()
. This meant that the common practice ofbuffer=malloc(1024)
actually used 2048 bytes. 1024 was an obvious choice, but in fact it was the worst possible choice. $\endgroup$setvbuf(…, malloc(BUFSIZ), …, BUFSIZ)
, where BUFSIZ is almost always defined as a power of 2. $\endgroup$