6
$\begingroup$

In the first high-level language (FORTRAN), lines of text would by default be treated as individual statements, except that a card which contained something other than an asterisk or C in column 1 and something other than a blank or zero in column 7 would be treated as a continuation of the previous line. In most subsequent languages which had a concept of "statements", they were either indicated by explicit ending delimiters (typically semicolons), by continuation markers placed at the end of the line (e.g. -_ in VB.NET), or by a grammar that would leave things unresolved at the end of a line (JavaScript).

If a language will be interactively processed by a REPL that receives lines of inputs, it's useful to have the text of a line indicate whether the contents of the line should be processed without awaiting further input. In all scenarios involving static source files, however, I would think the essence of the very first approach that was ever used (using something at the start of the line after the incomplete one, rather than at the end of the incomplete line itself) would be superior. A tiny amount of extra work might be needed to perform "lookahead" before processing each line, but if such a burden was tolerable for the first FORTRAN compilers it should be no less so today.

Have languages other than FORTRAN indicated continuations using a prefix on the line containing extra content, rather than a suffix on the incomplete line?

$\endgroup$
20
  • 3
    $\begingroup$ I don't know the answer to your question but I have a fun fact about the VB line continuation character. The line continuation character was added in VB 3 I believe. I was an intern on the VB team at the time. It was a HUGE amount of work for what seems like a trivial feature because everything -- the parser, the editor, the pretty printer, the debugger, the serialization model, everything -- had been written to assume one statement equals exactly one line. I learned a lot about the consequences of bad abstractions in those few months. $\endgroup$ Commented Jan 27 at 17:18
  • 1
    $\begingroup$ @EricLippert: I can appreciate that supporting any kind of line continuation would have complicated things considerably, but would the choice of trailing versus leading be an issue? I woudl think that having a prefix that could tell an editor "Don't try to reason about this line in and of itself", and having continuation lines be handled as part of handling the line above, would if anything make things easier for an IDE than having the tail of a line change the behavior of the next line. $\endgroup$ Commented Jan 27 at 18:12
  • 1
    $\begingroup$ This isn't exactly what you mean, but Python terminates blocks by dedents (i.e. the next line is not indented as far as the previous line), so a block is continued to the next line when the next line is prefixed with sufficient indentation. This applies in the CPython REPL when you want to execute a block, since you must enter a blank line (i.e. no indentation on the next line) in order to terminate it. That is, even though you have written the whole of a block statement, it's not "grammatically complete" until you write a dedent on the next line, so the interpreter knows it isn't continued. $\endgroup$ Commented Jan 27 at 19:19
  • 1
    $\begingroup$ It also means that the lexical grammar of Python in a source file is subtly different from the lexical grammar in the REPL, as an empty line in a source file does not terminate a block if it is followed by a line with the correct indentation to continue that block. This makes it so that you can't copy/paste an arbitrary Python statement into the REPL and execute it, which is a bit of an anti-feature. $\endgroup$ Commented Jan 27 at 19:25
  • 2
    $\begingroup$ FWIW, here's the code that handled it in the original FORTRAN: texdraft.github.io/fortran/fortran-10.html#line-1687 $\endgroup$ Commented Jan 30 at 8:13

4 Answers 4

3
$\begingroup$

VimScript, the scripting language for Vim, uses a leading backslash to indicate line continuation.

$\endgroup$
2
$\begingroup$

Yes.

SNOBOL 41 treats a + or . in column 1 as an indication that the current line is a continuation of the previous line.

http://berstis.com/s4ref/sntx3a.htm


1. I believe previous versions of SNOBOL do the same, but I'm a lot less certain about them.
$\endgroup$
1
$\begingroup$

The comments mentioned Python, but Python only uses something analogous for delimiting blocks, whereas line continuations need parentheses or \-endings - so in that regard it's again more like JavaScript.

The language that inspired Python's whitespace-based syntax takes the idea all the way though: in Haskell, lines are continued until the next line with the same indentation or an indentation level of a surrounding scope. Thus, the following is accepted:

main :: IO () main = do let x = 1 + 2 + 3 print x 

being equivalent to

main = do let x = 1 + 2 + 3 print x 

and printing 6. What causes the + 2 and + 3 to be treated as continuations is that they have sufficient whitespace on the left to be recognised as belonging to the definition of x.

By contrast, this triggers a parser error:

main = do let x = 1 + 2 + 3 print x 

A different example, to highlight that this has nothing to do with incompleness of the line fragments:

main = do let x = max 1 2 print x 

This prints 2 (x corresponds to max(1,2) in other languages). The following is syntactically legal too, but means something different (and won't typecheck)

main = do let x = max 1 2 print x 

I was always under the impression that Python took the indentation idea from Haskell (or its predecessor Miranda), but as Mister Miyagi comments neither appears to be historically correct. Indentation-based blocks were already used in ABC, whose prototypes included this feature before either Miranda or Haskell were released. Like Python, I don't think ABC used indentation for line continuation, so the ABC/Python and Miranda/Haskell approaches seem to be indeed two separate ways of doing a similar thing.

$\endgroup$
2
  • 2
    $\begingroup$ "The language that inspired Python's whitespace-based syntax [..]: Haskell" Erm, I thought Python took the indentation from ABC, which is older than Haskell. $\endgroup$ Commented Jan 31 at 17:45
  • $\begingroup$ @MisterMiyagi right. $\endgroup$ Commented Feb 2 at 12:03
1
$\begingroup$

COBOL used a continuation character (-) in column 7, for the same reason FORTRAN did: it was a multi-pass fixed-format line-oriented language.

$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.