Before the system had the ability to open resources as files, resources were opened using the predicates open_resource/2 or open_resource/3. These predicates provide somewhat better dynamic control over resources depending on whether the code is running from files or from a saved state. The main disadvantage is that having a separate open call requires rewriting code to make it work with resources rather than files.
- open_resource(+Name, -Stream)
- open_resource(+Name, -Stream, +Options)
- Opens the resource specified by Name. If successful, Stream
is unified with an input stream that provides access to the resource.
The stream can be tuned using the Options, which is a subset
of the options provided by open/4.
- Options that determine the binary/text type, encoding for text streams and whether or not the content should be checked for a BOM marker. The options have the same meaning as the corresponding options for open/4.
The predicate open_resource/3 first checks resource/2. When successful it will open the returned resource source file. Otherwise it will look in the program's resource database. When creating a saved state, the system normally saves the resource contents into the resource archive, but does not save the resource clauses.
This way, the development environment uses the files (and modifications) to the resource/3 declarations and/or files containing resource info, thus immediately affecting the running environment, while the runtime system quickly accesses the system resources.