DM4 p. 190 (referring to setting up library extension files) says:
Such a file should contain the directive System_file;
, as then other designers will be able to Replace
routines from it, just as with the rest of the library.
On p. 191, it says:
Because of this, Inform allows you to Replace
any routine or routines of your choice from the library… For example, if the directive Replace BurnSub;
is placed in your file before the library files are included, Inform ignores the definition of BurnSub
in the library files.
Given the stress on library files on p. 191 and the link to the System_file;
directive on p. 190, I seem to have made an incorrect inference that “library file” meant “file including a System_file;
directive”, and I thought that definition carried through to all documentation of the Replace
directive, including the current release notes to which you’ve previously directed me. (Thus my reference to “undocumented”.) Thank you for bringing my attention to this distinction!
FYI, you’re right about the compiler error for situations attempting to declare a routine already declared in a non-system file. In this scenario, the included file is not marked as a system file, there is no Replace
directive, and the Include
occurs before the definition of the routine with the same name in the “main” file.
$ inform -X '+include_path=optional,/usr/share/inform/6.31/module' testing-replace.inf
Inform 6.31 for Linux (10th Feb 2006)
Including optional file...
line 21: Error: Expected routine name but found RoutineA
> [ RoutineA
"optional/RoutineA.h", line 4: Warning: Routine "RoutineA" declared but not used
Compiled with 1 error and 1 warning (no output)
$ inform -X '+include_path=optional,/usr/share/inform6/library' testing-replace.inf
Inform 6.33 for Unix (10th May 2014)
Including optional file...
line 21: Error: Expected routine name but found RoutineA
> [ RoutineA
"optional/RoutineA.h", line 4: Warning: Routine "RoutineA" declared but not used
Compiled with 1 error and 1 warning (no output)
$ ./inform -X '+include_path=../i6/optional,/usr/share/inform6/library' testing-replace.inf
Inform 6.34 (21st May 2020)
Including optional file...
line 21: Error: Expected routine name but found RoutineA
> [ RoutineA
"optional/RoutineA.h", line 4: Warning: Routine "RoutineA" declared but not used
Compiled with 1 error and 1 warning (no output)
$ ./inform -X '+include_path=../i6/optional,/usr/share/inform6/library' testing-replace.inf
Inform 6.35 (in development)
Including optional file...
line 21: Error: Expected routine name but found RoutineA
> [ RoutineA
"optional/RoutineA.h", line 4: Warning: Routine "RoutineA" declared but not used
Compiled with 1 error and 1 warning (no output)
For 6.31, in the scenario where there is a Replace
directive for a routine, followed by an Include
directive for a file containing that routine, followed by a definition in the main file of that routine, there’s no compiler error:
inform -X '+include_path=optional,/usr/share/inform/6.31/module' testing-replace.inf
Inform 6.31 for Linux (10th Feb 2006)
Including optional file...
and the output from the program says:
This is RoutineA() from testing-replace.inf.
The same pattern is followed for 6.33, 6.34 and 6.35.
Interestingly, the compiler doesn’t complain about routine redefinition within the same (main) file (and uses the second definition) in any of these versions, when a Replace
directive (single-name variant) is in place. The same applies for two routine definitions in the same “library” file, when there is no competing definition in the “main” file. So there doesn’t seem to be any difference in behavior across recent versions in the absence of a System_file;
declaration.
Thank you for your patience on this topic. With any luck, this will be my last question about Replace!