3 ms·
Quick test: if you create a new namespace and import another file within that namespace, do its contents end up in that namespace? Included: ACS, awk, COBOL, E
by kazinator 10y ago
Quick test: if you create a new namespace and import another file within that namespace, do its contents end up in that namespace?
Included: ACS, awk, COBOL, Erlang, Forth, Fortran, most older Lisps, Perl 5 (despite that required files must return true), PHP, Ruby, Unix shells.
Common Lisp's LOAD binds the value of {star}package{star} to the value it held before LOAD was invoked. This means that the LOAD takes place in the same package, but if the file being loaded changes to a different package, that effect is lost when the LOAD completes.
In other words, the designers thought about this issue (how loading interacts with the package system) and made a clear decision: same package is used over the load, but the loaded file is prevented from altering the caller's current package: they decided that the parent being able to establish a package and read table for the loaded child is useful flexibility, but the reverse situation being error-prone.
That decision is a reasonable one. I thought about the same issue in TXR Lisp and copied the decision made by ANSI CL, recognizing its wisdom.
Note that when LOAD loads a compiled file, then the symbols in that file are not affected by the current package. They are not being read from source code any more. (That is no longer textual inclusion).
Lisp supports textual inclusion in the sense that you can load a file that is raw source code, without being forced to compile it first. That is useful and good; why not support such a thing? Being able to set up a package or read table and then do a bunch of loads which then take place in the context of that package is also useful and good.
Lisp doesn't force you into textual inclusion. Even for macros, you don't have to use textual inclusion. A module containing macros can be compiled with COMPILE-FILE. Then that file can be loaded as a compiled file, by the compiler, when other files are being compiled (files which need those macros).
Please, don't compare Lisp with C #include!