Optional dependencies for packs?

Would it be possible to have the ability to mark the dependency a pack requires as optional? My use-case is wanting to use inotify if available, but still have the rest of the library be usable even if running on a platform that doesn’t support inotify.

I could, of course, just not include the dependency in pack.pl, but then I would need to display a message prompting users to manually install the pack if they want to use those features, which seems suboptimal.

I think the idea is good. It would probably also need some idea about system requirements that tells Prolog that the inotify pack cannot be installed on the target, no?

The alternative is of course to detect the availability of inotify (using e.g., :- if(exists_source(library(inotify))). in your pack and provide the additional functionality if present. The overall idea (from first impression) to allow automatic updates on changed source files is worthwhile as a stand alone facility, I think. We could extend make/0 to deal with non-Prolog files and then use inotify to trigger make/0 automatically?

That would be ideal, but I suppose would require the individual packs to be able to indicate what they need (or just failing to install the pack wouldn’t be an error?). The alternative that @swi & I were discussing would be to just prompt the user “do you want to install this pack too?” when running pack_install/1.

That sounds like a good idea! Perhaps also make make/0 hookable, so one could register a predicate to run with the changed files?

Something like that. I guess you need something that defines a node in a dependency graph, allow adding dependencies and a command to make the node. The built-in system as it now is has a loaded source file as target, the source itself as dependency and consult/1 as command.

make/0 is fairly simple and I’d surely accept a patch to make it smarter :slight_smile:

1 Like

Dear Jamesnvc,

pack(lib) includes lib(suggests(PACK)).

A line like
:- lib(suggests(real)).

Will always succeed. If pack(real) is installed, then it is loaded.
Depending on the value of prolog_flag, lib_suggests_warns, you might get a warning message.

  • auto
    (default flag value), silent by default unless loading code presents option suggests_warns(true)
  • false
    never warn when suggested features are missing
  • true
    always warn when features are missing

"lib" pack for SWI-Prolog

Hope it helps,

Nicos Angelopoulos


1 Like

Oh excellent, thanks Nicos! That will be very helpful, thank you very much!