points by acqq 14 years ago

The proper list starts with:

   1956: Fortran I:
            PRINT 1, X
         1  FORMAT (F10.2)

Fortran was able to use the same format specification for more than one print statement, that's why the format statement is referenced by number. It was even able to do repeats, for example this code from 1956

        PRINT 2, X, Y, A, B, C, D, N
      2 FORMAT ( 3 ( F10.3, F10.4 ), I4 )

is an equivalent of the following C:

    printf( "%10.3f%10.4f%10.3f%10.4f%10.3f%10.4f%4d",
    x, y, a, b, c, d, n );

Moreover, C interprets the format specification at runtime, in FORTRAN the compiler uses it during the compilation.

Fortran was invented by John Backus and there was already a finished compiler in 1956:

"Programmer's Reference Manual Fortran Automatic Coding System For IBM 704"

http://www.fh-jena.de/~kleine/history/languages/FortranAutom...

I/O in the first Fortran, I believe including the FN.M syntax, was implemented by Roy Nutt, also one obvious genius:

http://www.smartcomputing.com/editorial/dictionary/detail.as...

eliasmacpherson 14 years ago

char format[10] = "%10.3f%10.4f%10.3f%10.4f%10.3f%10.4f%4d";

printf( format, x, y, a, b, c, d, n );

You can get similar behavior from C, reusing the format specification? No idea if this was true in the K&R days though.

  • acqq 14 years ago

    But not the repetition inside of one specification which I illustrated in the example (note the 3 before the braces in the 2 FORMAT), and much more important, no compile-time type checking and compile time code generation for output. In C it's a library call and most of the processing happens at the run-time. And yes I know of gcc checks.

    Still whoever uses some printf variant today, misses some aspects of what was working in 1956.

    • pcwalton 14 years ago

      Neat, I didn't know Fortran did printf right.

      OCaml and Rust both have compile-time format string checking and code generation as well.

    • eliasmacpherson 14 years ago

      I was only addressing your first point, not your second example which you demonstrated clearly earlier. The recursive syntax is impressive alright - thanks for sharing it. I was unaware of it, as I'm sure many others were. I was not suggesting C has a built in method for achieving the results of the second example. I'm not certain about the compile time versus execution time distinctions. The compiler behaviour could depend on the mutability of the objects. It's possible a C #define constant would cause different compile time behaviour to variables. I'm not a compiler expert in either language so I can't provide any insight in any case.

      Those GCC checks you mentioned are handy and would have avoided a bug in production code a colleague encountered a few years ago, but I imagine they are more recent than C in 1982, and certainly more recent than Fortran in 1956

      #define formata "%10.3f%10.4f"

      #define formatb(z) z z z "%4d\n"

      printf( formatb(formata), x, y, a, b, c, d, n );

      The example you've given is thought provoking!

rbanffy 14 years ago

I think you started your code on the wrong column... ;-)