mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.01k stars 118 forks source link

How to add external libraries in my project? #701

Open matteoredaelli opened 3 years ago

matteoredaelli commented 3 years ago

Hello

I would like to have something like

asserta(user:file_search_path(library, 'packs')

that is provided by swi-prolog in order to be able to use external libraries like

use_module(library(atom_feed_lib/atom_feed)).

My project folders are like

myproject/src/myprogram.pl
myproject/packs/atom_feed_lib/atom_feed.pl
myproject/packs/anotherlib/libfile.pl
pmoura commented 3 years ago

P.S. Historical note: the file_search_path/2 predicate (and corresponding mechanism) was introduced by Quintus Prolog and later copied by systems such as SWI-Prolog and SICStus Prolog.

dcnorris commented 3 years ago

Everything below the line is a terrible idea. It's so much better to follow this advice.

I tried creating a symbolic link under src/lib/ to make my project dir appear to be like (e.g.) tabling/, but to no avail:

?- use_module(library(precautionary/qbeta)).
%@ caught: error(existence_error(source_sink,library('precautionary/qbeta')),load/1)

EDIT: Ah, but if I then rebuild Scryer, it now sees my libs. Given how fast Rust rebuilds a project, this 'solution' causes no immediate difficulties for my efforts toward modularizing my code. Even when it comes time to release the next version of my R package, which will build Scryer as part of the installation, this extra line (ln -s ...) in the Makefile seems relatively harmless (what could possibly go wrong?) even if it does feel a little 'inelegant'.

%?- use_module(library(precautionary/qbeta)).
%@    true. % After rebuilding scryer-prolog
%@ caught: error(existence_error(source_sink,library('precautionary/qbeta')),load/1)
triska commented 2 weeks ago

This feature was also mentioned in the course of a discussion about environments: https://github.com/mthom/scryer-prolog/discussions/2435