This module provides a predicate for file opening which can use any term as an alias for the filename (i.e., symbolic filenames) instead of the usual constants which are file system path names of the actual files.
The correspondence between an alias and the actual file path is done dynamically, without having to recompile the program. It is possible to define the correspondence via facts for file_alias/2 in a file declared with multifile:alias_file/1 in the program: those facts will be dynamically loaded when running the program. Alternatively, the correspondence can be defined via shell environment variables, by defining the value of a variable by the (symbolic) name of the file to be the path of the actual file.
Open File with mode Mode and return in Stream the stream associated with the file. It is like stream_basic:open/3, but File is considered a symbolic name: either defined by user:file_alias/2 or as an environment variable. Predicate user:file_alias/2 is inspected before the environment variables.
Usage:
Declares File to be a file defining symbolic names via file_alias/2. Anything else in File is simply ignored.
The predicate is multifile.
Declares Alias as a symbolic name for File, the real name of an actual file (or directory).
The predicate is multifile.
The predicate is of type data.
:- use_module(mm). :- multifile alias_file/1. alias_file(myfiles). main :- p(X), display(X), nl.
Now, the file myfiles.pl can be used to change the file you want to read from without having to recompile the application. The current assignment is:
%:- use_package([]). file_alias(file,'mm.pl').
so the execution of the application will show the first line of mm.pl. However, you can change to:
file_alias(file,'main.pl').
and then execution of the same executable will show the first line of main.pl.