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"
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.
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
I'm not sure what the point of this is. It seems pretty petty. To wit, we could have just we well written...
MACLISP (1980):
(format t "Week ~R of the ~:R month of the year ~:@R~%" 15 102 1996)
--> Week fifteen of the one hundred second month of the year MDCCCCLXXXXVI
C/C++/Java/Python/Ruby:
...uh...
COMMON LISP:
(format t "Week ~R of the ~:R month of the year ~:@R~%" 15 102 1996)
--> Week fifteen of the one hundred second month of the year MDCCCCLXXXXVI
There are powerful print functions and then there are powerful print functions.
This is a very specific selection. There are plenty of modern languages that don't use printf semantics or C-like syntax. Too, there's languages from the 80s and 90s that did: Python (1991), R (1993), and PHP (1995) come to mind for direct printf analogs.
None of these are syntax. `printf` in C or scala/groovy is a function call, which relates to the language's API, the C++ use of streams is an API decision, Java being funky is due to its API (and its semantics to a lesser extent). The only language I can think of off the top of my head where print would be syntax would be python, and even then 1) that's only for versions <=2, and 2) the formatting would still be an API choice.
printf/scanf do have a syntax. But you're not wrong saying it is not part of the syntax of the language stricto sensu.
I personnaly don't like the printf/scanf style, which unfortunately often prevails in newer languages. I definitely prefer the string interpolation method, or just plain string concatenation.
> I definitely prefer the string interpolation method, or just plain string concatenation.
You're mixing things up; the point of printf is to format data, of which "%s / %s / %s" is a subset. Constructs like "0x%04x" or "%12s" really are about formatting.
Yes, but they're often used for "mere" interpolation, especially in languages where, rightly or wrongly, string concatenation is believed to be inefficient. I personally do this nine times out of ten, if only out of habit.
For my part, I've never personally liked the use of "+", in particular, to denote concatenation, for the (admittedly silly) reason that string concatenation is not commutative. If nothing else, it's a bit of a slippery slope to even more dubious operator overloads, though not nearly so much as C++'s bloody I/O "operators"!
It's not uncommon to use + for groups even if they're not abelian, esp. with near-rings.
This takes all its importance with duck-typing, as syntactic sugar of binary operators will be translated to a method call, e.g in Ruby a + b becomes a.+(b) [0]. while in Python it's a.__add__(b) [1]. The result might be commutative, but the call and evaluation order certainly is not.
Fortunately, Java is "developing" with regard to its expressiveness.
Using Scala and co only brings you a part of the way, especially if you have to interact with Javaesque APIs like in Android, where you have dozens of different abstract classes (or sometimes interfaces) begging for anonymous inner classes.
Does anyone else find a headline about the emergence of traditional orthodoxy in syntax that omits a closing paren in favor of an emoticon to be maddeningly ironic?
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...