# Optional dependencies for packs?

**URL:** <https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160>\
**Category:** Request For Comments\
**Tags:** packs\
**Created:** [July 13, 2021, 9:33pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160 "2021-07-13T21:33:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [July 13, 2021, 9:33pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160/1 "2021-07-13T21:33:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 15, 2021, 2:30pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160/2 "2021-07-15T14:30:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [July 15, 2021, 2:38pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160/3 "2021-07-15T14:38:07Z")

</div>

> [@jan](#):
>
> 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?

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.

> [@jan](#):
>
> 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](https://www.swi-prolog.org/pldoc/doc_for?object=make/0) to deal with non-Prolog files and then use inotify to trigger [make/0](https://www.swi-prolog.org/pldoc/doc_for?object=make/0) automatically?

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [July 15, 2021, 2:53pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160/4 "2021-07-15T14:53:21Z")

</div>

> [@jamesnvc](#):
>
> That sounds like a good idea! Perhaps also make [make/0](https://www.swi-prolog.org/pldoc/doc_for?object=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 🙂

---

<div class="post-metadata">

**Author:** ![nicos](https://avatars.discourse-cdn.com/v4/letter/n/7feea3/32.png) [@nicos](https://swi-prolog.discourse.group/u/nicos)\
**Post date:** [July 17, 2021, 9:04pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160/5 "2021-07-17T21:04:40Z")

</div>

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

See  
["lib" pack for SWI-Prolog](http://eu.swi-prolog.org/pack/list?p=lib)

Hope it helps,

## Nicos Angelopoulos

> **[Nicos Angelopoulos](https://stoics.org.uk/~nicos/)**
>
> logic programming

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [July 17, 2021, 11:28pm UTC](https://swi-prolog.discourse.group/t/optional-dependencies-for-packs/4160/6 "2021-07-17T23:28:51Z")

</div>

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