5 ms·
You don't see this every day: https://github.com/dspinellis/unix-history-repo/blob/Research-PDP7-Snapshot-Development/lcase.b https://github.com/dspinellis/uni
by vandahm 4y ago
You don't see this every day:
https://github.com/dspinellis/unix-history-repo/blob/Research-PDP7-Snapshot-Development/lcase.b https://github.com/dspinellis/unix-history-repo/blob/Researc...
Is this B, or is it BCPL? What would have compiled this code back in the day?
- swatcoder 4y agoI don’t know, but I love how clearly and concisely it expresses what would later become ubiquitous as do-while and continue. That’s poetry. Nice find.
- stingraycharles 4y agoI love how thin the layer above assembly is: without knowing B, is my interpretation correct that this function effectively “inherits” the stack of the calling function? In other words, rather than passing function arguments and let the compiler deal with it, you’re supposed to push the string you want to lcase onto the top of the stack? Reminds me a lot of writing my own compiler/assembler in university, where it’s expected that all this happens automatically nowadays.
- anyfoo 4y agoHmm, don’t think so. The function does not operate on a string, it seems to read a character using read() and write it back, transformed, using write(). Given that the function is named main, it’s probably the top level function anyway (from the programmer’s point of view, often the OS actually calls into a different function that is part of the language runtime, e.g. _start, which in turn calls main eventually, but that is usually hidden from the programmer).
- messe 4y agoNo, that's not correct. It reads the string from standard input. A C translation would look like this: main() { int ch; while ((ch = read()) != 4) { if (ch > 0100 && ch < 0133) ch = ch + 040; if (ch == 015) continue; if (ch == 014) continue; if (ch == 011) { ch = 040040; write(040040); write(040040); } write(ch); } } A more modern C version would look like: #include <stdio.h> int main(void) { int ch; while ((ch = getchar()) != -1) { if (ch > 0100 && ch < 0133) ch = ch + 040; if (ch == 015) continue; if (ch == 014) continue; // No need to handle tabstop specially putchar(ch); } }
- jibal 4y agoThis is the main function ... there is no calling function. Nor is a string on the stack being accessed.
- pm215 4y agoWikipedia's article on B says that BCPL used := for assignment and = for equality tests, whereas B used = for assignment and == for equality. Assuming that's correct, this must be B code.
- projektfu 4y agoIt's B. BCPL has "LET MAIN() BE $(..." instead of "main $(...". Running B was a challenge on the PDP-7 but easier on the PDP-11, apparently, because of the increase of memory size. The linked document has an interesting history about compiling B to threaded code, a form of interpreted code, and then to machine language. B never really made the jump to a full-fledged citizen because it quickly got replaced by C, although BCPL was popular for a long time. https://www.bell-labs.com/usr/dmr/www/chist.html https://www.bell-labs.com/usr/dmr/www/chist.html
- mftb 4y agoYea, I have to say, to me, this is cool. Glad to see this sort of history being preserved.
- judge2020 4y agoIs that truly from 1970? For example, that commit's grandparent seems to have been specifically crafted to use "Date: Thu, 1 Jan 1970 00:00:00 +0000" https://github.com/dspinellis/unix-history-repo/commit/185f8e834621f40c2c49647d08ec6e17acb6bcc0.patch https://github.com/dspinellis/unix-history-repo/commit/185f8....
- anyfoo 4y agoThat’s 0 in Unix epoch time (guess why!), so seems more like a missing timestamp than a crafted one. The fact that the linked file does not have a 0 timestamp, but a slightly later one, suggests it's valid, or at least intended to be valid.
- Nition 4y agoI recall that in A Deepness in the Sky by Vernor Vinge, a space sci-fi set in the far future, they're still using Unix time underneath many many layers of abstractions, and with their cultural context they guess that humanity must have set it to start with the moment mankind first travelled into space to land on the Moon.
- anyfoo 4y agoHah, plausible. Not far off timewise, and yet totally wrong, but understandable how such a conclusion could be made.
- Erlangen 4y agoSo auto is used as a keyword here. Maybe C inherits this never-used auto from B?
- veltas 4y agoauto stands for 'automatic', because such variables are automatically allocated for each function invocation. In C it became redundant because base types were added, and so the base type could start the definition (auto was still permitted with default base type of int until C99 I think). auto in B is a bit like 'let', it starts a declaration, along with 'extrn'.
- marcodiego 4y agoThey had "auto" vars in 1970. WG14, the ISO work group that maintains the C programming language specification, has just recently discussed acceptance of __auto_type. EDIT: ops, the "auto" here means automatic allocation.
- hoten 4y agovery weird that two characters - $( and $) - were used before { and } did old keyboards not have curly braces or what?
- kps 4y ago{} were added to the 1967 revision of ASCII, along with `|~ and lower case. (EBCDIC never got them in the base character set, only in alternate ‘code pages’.)
- usr1106 4y agoI remember in 1990 IBM sponsored a small 370 for our university. I fiddled weeks to get curly braces to work correctly. We were all used to work with Sun workstations or at most VAXen at the time. It was unbelievable how complicated this was in the IBM world. They were still living in the world of full-time machine operators. My colleagues were glad I did it, my professor who had not programmed for years and was moving in higher spheres was not impressed I had spent so much time on it when he learned about it later.
- mseepgood 4y agoIn C you can still use the digraphs <% and %> as an alternative to curly braces: int main() <% printf("hello, world\n"); return 0; %>