True, but the difference between C and Haskell hash-bangs is that GHC Haskell provides an interpreter.
GCC hash-bang is still an edit-compile-link-debug cycle. Just like with Python and Ruby, Haskell hash-bang accelerates the cycle by jettisoning the compile and linking steps.
The Rosetta examples show a solution that only compiles the C file if it has not been previously compiled, or if it has a newer modification timestamp than the executable.
Doesn't the (necessarily loose) coupling of executables with source files create its own challenges? Or does it track the object file too, in which case we have 3 files, not 1, to manage simultaneously?
The benefit of scripts is that each file is a self-contained single source of truth.
In the case of one .c file, there doesn't have to be an object file; you can go straight to executable "cc prog.c -o prog".
Python implements a caching scheme for .pyc files; maybe it's not a scripting language ...
If I were to venture an opinion on why C (in its usual implementations) is not a scripting language it would be:
- no interactive prompt (REPL).
- no reloading of code (other than clumsy, fragile, platform-specific shared lib mechanisms).
- no execution of "top level forms": a program's entry point is a specific function (main on hosted implementations). When, e.g., Lisp code is compiled, the effect of loading the compiled file is still the same as of the source file: the top-level forms (now in a compiled form) are executed one by one. (What's a "script"? A file with instructions to be run one by one.)
- no late binding; in fact, no program at all, unless all external references are satisfied. Scripting languages can run code that contains references to unknown global variables, or calls to unknown functions. These can be loaded late.
> When, e.g., Lisp code is compiled, the effect of loading the compiled file is still the same as of the source file: the top-level forms (now in a compiled form) are executed one by one. (What's a "script"? A file with instructions to be run one by one.)
Fun fact: the SBCL implementation of Common Lisp actually adds a shebang to its compiled, binary Lisp files, so you can compile your Lisp script and then execute it from the shell.
I just improved this tonight. If the original program is unsuffixed, and so its hash bang line uses the --lisp option to say "treat this as Lisp source" that option is translated to --compiled, so that if the compiled file is also unsuffixed, it will be properly treated as compiled.