I’m still working on getting a SICStus-based application to run on SWI using expects_dialect(sicstus)
and am extending SWI’s library(dialect/sicstus) in the process. At the moment, SWI’s library(dialect/sicstus) seems to provide almost only SICStus 3 predicates/libraries, so I started (locally) implementing various SICStus 4-only predicates/libraries that are needed by the application I’m working on. However, I ran into an issue with trying to add SICStus 4 support to SWI’s library(dialect/sicstus) while keeping the existing SICStus 3 support.
Many APIs are identical in SICStus 3 and 4 or were only slightly renamed, but some APIs have changed significantly between SICStus 3 and 4, for example the file system interaction API. On SICStus 3, library(system) provided a few file system predicates like file_exists
, make_directory
, rename_file
, delete_file
, etc. On SICStus 4, the file system API has been moved out of library(system) and completely redesigned as a separate library(file_systems). One of the major changes is that library(file_systems) treats files and directories as completely different things. For example, on SICStus 3, delete_file
from library(system) could delete both files and directories, whereas on SICStus 4, library(file_systems) provides separate delete_file
and delete_directory
predicates that accept only regular files or only directories.
When I added a library/dialect/sicstus/file_systems.pl in my local SWI build to emulate the SICStus 4 library(file_systems), I ran into the problem that I couldn’t import both library(system) and library(file_systems) at the same time, because some of the SICStus 3-compatible file system predicates from library(system) conflicted with SICStus 4 library(file_systems) predicates with the same names:
?- expects_dialect(sicstus).
true.
?- use_module(library(system)).
true.
?- use_module(library(file_systems)).
ERROR: import/1: No permission to import file_systems:rename_file/2 into user (already imported from system)
ERROR: import/1: No permission to import file_systems:file_exists/1 into user (already imported from sicstus_system)
ERROR: import/1: No permission to import file_systems:delete_file/1 into user (already imported from system)
true.
On real SICStus 4 this works without problems, because SICStus 4 library(system) no longer provides the SICStus 3 file system predicates:
| ?- use_module(library(system)).
% loading .../bin/sp-4.5.1/sicstus-4.5.1/library/system.po...
% module system imported into user
% ...
% loaded .../bin/sp-4.5.1/sicstus-4.5.1/library/system.po in module system, 6 msec 34656 bytes
yes
| ?- use_module(library(file_systems)).
% loading .../bin/sp-4.5.1/sicstus-4.5.1/library/file_systems.po...
% module file_systems imported into user
% ...
% loaded .../bin/sp-4.5.1/sicstus-4.5.1/library/file_systems.po in module file_systems, 4 msec 186464 bytes
yes
I’m not sure what would be the best way to handle this. I can’t just merge the definitions of the conflicting predicates (and have one module import it from the other), because for example with delete_file
the behavior differs between the two versions/libraries (see above). I need some way to have use_module(library(system))
import only the SICStus 4-compatible predicates.
SICStus 4 still provides the SICStus 3 libraries, just renamed with a 3
at the end - e. g. SICStus 4 library(system3) is SICStus 3 library(system). SWI’s SICStus emulation could do the same, although this would break some existing code relying on the SICStus 3 emulation. It would also be possible to separate emulation for the two versions completely, i. e. have both expects_dialect(sicstus3)
and expects_dialect(sicstus4)
(with expects_dialect(sicstus)
redirecting to sicstus3
for compatibility?). Or possibly the SICStus 3 support could be removed entirely in favor of SICStus 4 (I have no idea how much SICStus 3 is still used in practice).