71

In the operating system (DOS) of IBM PCs, newlines were represented by a carriage return (CR) character, followed by a line feed (LF) character. The motion of a printer or teletype receiving such a combination would be first to move to the left, then down, and can be drawn this way:

---
|
v

or (if your browser font supports this)

However, the keyboards of those same IBM PCs used a different symbol on the return key: an arrow first drawn down, and then to the left.

   |
<---

or

Why didn't the return key symbol match the motion of a CR-LF?

(If the intent was to have a symbol for just the CR, |<--- () would have been better.)

DrSheldon
  • 15,979
  • 5
  • 49
  • 113
  • 64
    God bless stack exchange for its curious and absurd questions, and equally curious and absurd answers. I have used cr/lf all my life, and never once had to think about it being backwards until today! Now, I will be incapable of not thinking about it every time I press "enter"... like now! – Cort Ammon Mar 19 '20 at 19:39
  • 6
    I'm surprised, given the Retrocomputing readership, that no-one pulled you up on your pressing Enter rather than pressing Return. (-: – JdeBP Mar 20 '20 at 21:57
  • I've seen a few .txt files which used LF-CR... – grawity Mar 21 '20 at 11:18
  • 6
    |<-- is a backwards tab – Thomas Weller Mar 21 '20 at 12:12
  • 14
    There used to be this thing known as a "typewriter". The carriage return lever on it would first scroll up the paper, then slide the carriage to the right, so that the left side of the paper was ready to receive more printing. – Hot Licks Mar 21 '20 at 22:59
  • 5
    While I can't tell you the history of why the decision was made, regardless of what order the CR and LF are sent or physically carried out I have always thought that the visual metaphor makes sense the way it is: enter/execute the command (downward flowchart direction) and then go back to the beginning of the line to wait for a new command. If the arrow went back to the beginning of the line before going down, then every time I press it some part of my subconscious would think that I'm deleting the command I just typed. – jez Mar 22 '20 at 00:33
  • Key to the history of CR+LF is the timeframe 1963-1968. At this time, computers began using the ASR 33 Teleprinter as a console interface. I'm thinking of the DEC PDP-4 through PDP-10, but there are plenty of others. You can review the history here. – Walter Mitty Jul 15 '20 at 11:00
  • 1
    Get an old fully-manual typewriter and use it a bit. The icon will make sense then. – Thorbjørn Ravn Andersen Jul 15 '20 at 13:00
  • @ThorbjørnRavnAndersen: Do not make assumptions about me. I did have such a manual typewriter, and it was just as likely to make either of the two possible movements. – DrSheldon Jul 15 '20 at 14:27
  • 1
    @drsheldon one with an arm to return the carriage? Sounds like it needed to be oiled then – Thorbjørn Ravn Andersen Jul 15 '20 at 16:26
  • @HotLicks, I always made a point of sliding the carriage by using the wheel section then using the advancer lever to scroll the sheet. But, then again, I always was a bit of a rebel :-) – paxdiablo Apr 13 '22 at 08:37
  • 2
    I wonder whether linefeed first may have been advantageous to get the just-laid-down ink out of the way in case the carriage return may have smudged it. – paxdiablo Apr 13 '22 at 08:41
  • 1
    I think the sequence was LF, CR, DC1 or DC3. The DC1/DC3 was just a dummy character to prevent the teletype from typing the first character of the next line in the centre of the page. – cup Apr 19 '22 at 21:25
  • I wonder when and which machine first changed "return" to "enter". Some non-English-speaking countries never made the change, e.g. in Chinese they still call it "Hui-Che" (return carriage). – user3528438 May 03 '22 at 03:05

3 Answers3

61

Even though the CR usually goes before the LF in ASCII text, most printer mechanisms actually perform the LF before, or during, the CR. So the shape of the arrow is actually accurate.

This is even true of mechanical typewriters, in which the carriage is returned through a physical lever which, before enough force is transmitted through it to move the carriage, moves sufficiently to advance the page by one line. CR is sent first because it generally takes longer to perform the carriage movement than the line feed.

Chromatix
  • 16,791
  • 1
  • 49
  • 69
  • 1
    This begs the question why it's traditional for the text to be CR LF instead of LF CR since that is what actually happens. – Captain Man Mar 19 '20 at 14:20
  • 23
    @CaptainMan Because the carriage return action usually takes takes longer than the line feed action, so you want it to start first even it's only by the fraction of a second it takes to transmit one character. –  Mar 19 '20 at 14:32
  • @RossRidge: I wonder if there would have been any extra cost to assigning the CR and LF codes so that any code matching 000 1xx1 would reset the carriage and any code matching 000 101x would advance the paper? Then 000 1011 would naturally have reset the carriage and advanced the paper. – supercat Mar 19 '20 at 15:32
  • 4
    @supercat : Many TTYs implicitly LFed on an explicit CR (duplicating typewriter behaviour). On those models, CR and CRLF were already equivalent. – Eric Towers Mar 19 '20 at 17:03
  • @EricTowers: My first thought was that the ability to underline text using CR without LF would have been recognized as useful, but then I remembered that underline wasn't part of the original ASCII set. – supercat Mar 19 '20 at 17:05
  • 7
    @supercat Bolding via typing a line, issuing CR without LF, then retyping the line was a common operation on ttys, and the vestiges of it still appear sometimes in Unixy systems. – Russell Borogove Mar 19 '20 at 20:18
  • @RussellBorogove: I know such things were common under Unix, but of course the invention of ASCII substantially predates Unix. – supercat Mar 19 '20 at 22:53
  • 8
    @supercat Bolding by typing a line, throwing the carriage return lever, rolling the paper back a line, and retyping the line was also a common operation on typewriters. ;) – Russell Borogove Mar 19 '20 at 23:55
  • @RussellBorogove: How did the effectiveness of that compare with simply hitting the keys harder? Unless a ribbon was really faded, effective bolding would require shifting the second strike relative to the first. – supercat Mar 20 '20 at 00:17
  • 15
    @supercat Mechanical tolerances, while quite good, were just sloppy enough that the second pass would be shifted enough to give a really good bold -- much better than a harder physical strike. Check out https://uniqcode.com/typewriter/ – Russell Borogove Mar 20 '20 at 00:20
  • ...with brokenness set to 22 and ribbon ink set to 250. – Russell Borogove Mar 20 '20 at 00:27
  • 1
    Actually, the text traditionally sent by the host was not CR+LF. See for example the superbee-xsb terminal type. It was CR+long-delay+LF or CR+lots-of-pad-characters+LF. – JdeBP Mar 20 '20 at 21:08
  • @JdeBP: Some devices may have required a long delay, and MS-BASIC offered an option to configure pad characters after an LF, but I don't recall any devices using pad characters between CR and LF. Maybe some did, but CR+LF, in that order, is by far the most common multi-character newline sequence. – supercat Jul 15 '20 at 16:37
  • Note that mechanically LF first followed by the carriage moving is the better order, to avoid grot around the print head from smudging the fresh text... – Lou Knee Oct 02 '20 at 13:07
  • @LouKnee Surely if that was a concern, the same grot would smudge the ink immediately after impact? – Chromatix Oct 03 '20 at 07:18
  • 1
    @chromatix I've long forgotten the proper name for the things, but ribbon-based typewriters/printers had thin metal shields either side of the slot for the type/print-head/whatever to punch through, to keep loose ribbon off the paper and smooth out creases from the paper: tiny scraps of paper - often fragments of tractor strip - got stuck behind those a lot. But grot trapped behind the leading shield will at least stay clean. Grot under the trailing shield will smudge the text, but on a typewriter the user would notice and clean up within a few characters. Maybe "reduce" rather than "avoid". – Lou Knee Oct 03 '20 at 17:11
  • @LouKnee: If resetting the carriage will take longer than advancing the paper, and the actions can overlap but can't be started simultaneously, starting the CR first will be mechanically better than starting the LF first. – supercat Apr 19 '22 at 18:18
  • @supercat I don't see that: the moment the print head starts its CR motion it will potentially smudge fresh print, so to me it would always make more sense to do the LF first. There again, I'm prioritising quality over speed, and my experience is (was) primarily consumer dot-matrix printers rather than datacentre "line printers" - maybe those had better head designs or better quality paper? – Lou Knee Apr 21 '22 at 16:19
  • Early teleprinters needed to print each character at a fixed amount of time (typically less than 1/10 of the time required to transmit a character) after the character came over the wire. Trying to print a character while the print head was moving would have far worse effects than any kind of smudging that could otherwise be affected by operating sequence. Note that line printers are completely different from teleprinters, and low-speed "computer printers" don't have the same timing constraints as teleprinters, since a computer can hold off on sending text until the print mechanism is ready. – supercat Apr 21 '22 at 16:31
  • On an ASR-33 teletype, if the print head isn't near the left edge of the paper, sending a CR followed by a printable character will result in the latter character being printed while the print head is in motion. If LF were sent before CR, it would be necessary to follow the CR with a non-printing character to prevent this. While one could use the sequence LF+CR+NUL between lines, this would add an extra 1/10 second to transmission time for every line sent. Teleprinter output wasn't designed to be particularly attractive, so any smudging that might result would have been tolerable. – supercat Apr 21 '22 at 16:35
42

Chromatix' answer already perfectly nails the technical background. Especially the reference to classic typewriter mechanics, predating any TTY or terminal, where the symbol used quite closely follows the hand movement when issuing a new line.

Historically it may be interesting to look at the development. The combined function as a single key was only introduced with electric typewriters - like the Friden Flexowriter with 'CAR RET'. Even as late as 1961, when the new IBM Selectric was introduced, keyboards didn't feature the symbol but had 'Return' written in text. The same was true for IBM's first dedicated terminal system, the 1050 (and that was the basis for the /360 console).

It wasn't until the 2741 in 1965 that the symbol found its way onto the key cap - and stayed there until today.

Noteworthy here is maybe that neither CR nor LF was used in its mainframe environment, but NEL - Next Line - which in turn wasn't considered part of an input line but part of the protocol.

While using CR/NL instead of NL/CR may support a speed-up due to the way that TTY/typewriter mechanics operate (*1), this sequence also adds freedom in further transmission optimisation. Many TTYs had the ability to combine CR and LF into a single function (often switchable), to reduce the number of characters to be transmitted/stored (*2). Doing so makes more sense on LF than on CR, as CR alone does have a useful application for overwriting a line - like adding an underline or some other overstrike, while LF always advanced to the next line, which doesn't make much sense without repositioning the carriage as well.

As a result, TTYs configured for automatic CR on LF would act the same, no matter whether only a LF or CR/LF was sent, being agnostic to either variant, but would still allow overwrite with CR alone.

This is the reason why UNIX and other TTY-based systems of that time use LF to mark a line end. They expect TTYs (as well as glass TTY) to be set to include an implied CR when LF was received. Here it was less of a speed concern, but simplification of text handling as now (like with NEL) a single character symbolized line end, while still keeping compatibility with (TTY) output equipment, e.g. when dumping a file.


Side note about symbol usage: During the 1930s European TTY manufacturers replaced country specific labels, like German WR/ZL for CR/LF, with symbols. Using < for CR and (Triple Bar) for LF.


*1 - Being processed by independent hardware, thus able to act in parallel.

*2 - Depending on the device at the cost of inserting additional space.

Raffzahn
  • 222,541
  • 22
  • 631
  • 918
  • 1
    Re, "simplyfication of text handling" The point wasn't just to make it simpler. The point was, to decouple the encoding of text in a file or, the text stream output by a program, from the requirements of any particular output device. Also note: It could be that the output device itself was configured to correctly interpret the LF character, or (more often than not, is my guess) the line discipline (a.k.a., "line driver") would convert the NL to an appropriate sequence of control characters and/or time delays. – Solomon Slow Mar 19 '20 at 11:42
  • @SolomonSlow The considerations predates the existence of 'line discipline'. During the 60s it was still common, that machines had no OS, or it was simply ignored - much like 20+ years later with PC-DOS programming. Also, note that 'decoupling' is just a way of saying 'simplifying' - isn't it? – Raffzahn Mar 19 '20 at 12:42
  • 1
    Did CR-on-LF TTYs predate Multics (1964)? – Stephen Kitt Mar 19 '20 at 13:00
  • 5
    @Raffzahn, Yes The problem (application programs needed to be aware of control codes and timing requirements for a specific teleprinter) existed before the solution (UNIX translates \n into whatever sequence of CR and LF and NULs will make the teleprinter happy) was invented. I personally remember writing application code for some non-UNIX minicomputer (or maybe a micro, not sure), and having to find out the right number of NUL characters to send to prevent the first character of the next line from being struck while the print head still was in-flight back to the home position. – Solomon Slow Mar 19 '20 at 13:47
  • I noticed you mention the "enter" used to say "CAR RET" and also mention some symbols used < for CR. Is that why ^ is called a "carret"? – Captain Man Mar 19 '20 at 14:22
  • 3
    @CaptainMan LOL. No, but that's a cool way for a fake explanation. Caret is Latin and means 'he/she is missing (something)' (third person singular of careo). When editing/correcting a text (back before computers) an upward chevron was used (below the line) to mark where something had to be inserted - which is why a text cursor nowadays is called a caret, as it's were text gets inserted (when typing). In French it also has the meaning of turtle. < for CR is simply a symbol showing that the carriage will be moved to the left. Symbols save the effort to make country specific keycaps. – Raffzahn Mar 19 '20 at 14:55
  • @StephenKitt Yes. Implied CR was for one available on Flexowriters, but as well on mechanical TTY like the 1958 Siemens T100. After all, it's CR was done via a spring and all needed to add the functionality was an additional lever releasing that spring as well with LF. I still remember being trained to use it accordingly during service (at that time 1979 with the successor T1000 model). – Raffzahn Mar 19 '20 at 14:58
  • I spent several years writing drivers and diagnostics for disk and tape drives. Development usually started on a PDP-8. I wrote everything in assembler. A CR input would be mapped to a CR/LF, but it could be a LF/CR, the peripheral TTY did not care. The Teletypes were marked CR, but some IBM and CDC terminals marked keys as NL. On the Teletype, CR meant CR and LF meant LF, and a CR would be mapped to echo out a CR/LF combination. To overprint (bold) the characters would be printed, then a CR, then printed again. – mongo Mar 19 '20 at 19:04
  • @DrSheldon Thanks. I wouldn't mind, as he was the first to point out the core issue. I just added bells & whistles. – Raffzahn Mar 19 '20 at 19:15
  • 2
    @Raffzahn Just for the sake of completion, the turtle sense of French caret is unrelated to the Latin verb – it’s a borrowing from Spanish carey, which in itself is a Taíno word (from the Caribbean). The final t in caret is purely orthographic; they could just as well have spelt it caré or carai(e) instead. – Janus Bahs Jacquet Mar 19 '20 at 23:31
  • 2
    @JanusBahsJacquet Sure, I'm aware of that, still looking at the symbol, it seams related, a small turtle crawling along below a text line ... don't you think so? Not, when I comes to French spelling (English as well) , I do firmly belive it's a topic to be spared until human kind has reached lasting world peace and mastered FTL travel. – Raffzahn Mar 19 '20 at 23:39
  • See https://unix.stackexchange.com/a/411830/5132 and comments for Multics defining LF as both carriage return and line feed for device independent terminal I/O. – JdeBP Mar 20 '20 at 21:02
  • This is incorrect... "symbol used quite closely follows the hand movement when issuing a new line." The hand movement on a manual typewriter is opposite the symbol. You are pushing the platen to the right to move the start position for the next character to the left. The character position translates across the platen similar to the symbol. Otherwise the platen would be fixed in space and a moving typewriter hanging from it would be really hard to use. I have put in an edit to correct this but I'm making sure its understood here if it doesn't go through. – Rowan Hawkins Apr 19 '22 at 19:11
  • @RowanHawkins Of course I do not know what typewriter you're using, but the one right next to me does, when operated, first turn the platen to advance to the next line (vertical movement). Only when the next line is reached, the horizontal movement of the whole carriage is performed. So down first (↵). – Raffzahn Apr 19 '22 at 19:43
  • @Raffzahn: I think his point was that on most typewriters, a carriage return is accomplished by moving the carriage to its rightmost position (constrained by the margin tab), which will move the left side of the paper toward the place where the type bars strike. – supercat Apr 19 '22 at 20:17
  • @Raffzahn That is correct -- for the platen movement, which is my point. The HAND movement, using you left hand pushing the lever on the platen, is directly to the right. That has nothing to do with the symbol. Once typewriters went electric the CR was executed first since that took the most time and the LF happened some time during the return it was hard to see on a normal typewriter, but across 120 or more columns on a wide printer it happens someplace in the middle because the CR could take a more than a second. Where the LF is a fraction of a second. – Rowan Hawkins Apr 19 '22 at 20:21
  • 1
    Just like how the possessive of the mix is the mix’s, so too is the possessive form of Chromatix only ever *Chromatix’s* with an apostrophe plus s. You cannot just add an apostrophe the way you can with the answers you get from all those nasty, biting chroma ticks that pass along diseases like color blindness. :) – tchrist May 02 '22 at 20:50
-3

Just a quick comment on UNIX and actual teletype printers like the Dec LA120. Whether or not the enter key sends CR or a CR/LF is completely dependent on what TERMCAP (Terminal Capabilities) profile you are using for the interface(tty). I have several files of ASCII art which were explicitly designed to be printed on 120 column form-feed paper where inline CR's were not followed by LF's so that the printer could over-type to make darker text in the resultant print.

The platen is not able to move the impact area up the sheet it just prints the line and (other than a full CR) to the left via VT character codes which is what an LA120 uses. When you were using an LA120 as your terminal interface pressing backspace actually printed a ^H and then the new character. It would not move the print head one space back because you wouldn't be able to clearly read the over-struck character.

These ASCII Art files were designed to be large images, multiple sheets wide in many cases. The largest complete one I have is a lunar scene which was made to be 5 sheets (around 5 feet) wide though most are only 2 wide.

Any place you see VTxxx or LAxxx in a terminal file, those terminals were all defined by DEC (Digital Equipment Corporation) including the color capable terminals.

Rowan Hawkins
  • 915
  • 8
  • 18
  • 2
    I don't see how this addresses the question that was asked. You appear to be "begging the question" - if you want to answer a different question, the best way to do that is to ask the different question yourself. You obviously have useful information to impart, but doing so as an answer to a question asking something different isn't the right way to go about it. – Toby Speight Apr 20 '22 at 19:51
  • 1
    Yeah the hazards of answering too late at night. I've decided to ask my own question about these files and will strip this down to something that will fit in a comment which is why I originally did the answer – Rowan Hawkins Apr 21 '22 at 00:17
  • Please add a link in a comment here when you do - I'm looking forward to that Q&A. Thanks! – Toby Speight Apr 21 '22 at 06:17