Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request ensure_loaded/1 [ISO 7.4.2.8] #5

Open
ghost opened this issue Jul 23, 2021 · 4 comments
Open

Feature request ensure_loaded/1 [ISO 7.4.2.8] #5

ghost opened this issue Jul 23, 2021 · 4 comments

Comments

@ghost
Copy link

ghost commented Jul 23, 2021

Isn't ensure_loaded/1 a directive defined in the ISO core standard [ISO 7.4.2.8].
Currently it seems to be implemented by GNU Prolog as follows:

handle_directive(ensure_loaded, _, _) :-
    !, warn('ensure_loaded directive not supported - directive ignored', []).

Wouldn't it be possible to bring ensure_loaded/1 to GNU Prolog. I understand
that it might be difficult, because of the various stages and artefact transformations
involved in GNU Prolog. But maybe a little separate compilation and later linking

would do the job. So that an ensure_loaded/1 directive would spawn a separate
compilation, put the artefact on a list, and at the end of a consult batch all
separate artefacts are linked together or otherwise integrated.

@didoudiaz
Copy link
Owner

ensure_loaded/1 is not yet implemented (it has some issues for a native compiler). gprolog proposes the ensure_linked/1 directive which could help you.

@ghost
Copy link
Author

ghost commented Jul 27, 2021

Currently the work around is to use include/1. But include/1
is not smart, it cannot deal with an import graph. The main
benefit of ensure_loaded/1 would be to avoid duplicate

include/1, which is not part of the requirement of include/1.
So one workaround would be if one could define user
directives, like:

:- dynamic(visited/1).

ensure_loaded(Path) :- 
     visited(Path), !.
ensure_loaded(Path) ;-
     assertz(visited(Path)),
     include(Path).

@pmoura
Copy link

pmoura commented Jul 28, 2021

ensure_loaded/1 is not yet implemented (it has some issues for a native compiler). gprolog proposes the ensure_linked/1 directive which could help you.

As a side note, Logtalk provides the functionality of the ensure_loaded/1 directive. See:
https://logtalk.org/manuals/userman/programming.html?highlight=reload#flag-reload

@ghost
Copy link
Author

ghost commented Aug 10, 2021

Logtalk is not ISO core standard compliant in the way it deals
with Prolog texts. The minimum Logtalk would need to provide would
be include/1 and ensure_loaded/1. But it begs the question whether

any useful semantic can be made, Logtalk compilation units have
a name braket. On the other hand the ISO core standard indeed specifies
ensure_loaded/1 based on include/1. It mentions include explicitly:

Unbenannt

But there is a small gap, the standard doesn't elaborate when
Prolog text designators denote the same Prolog text. So I have
a new proposal, assuming a predicate absolute_file_name/2 that

then is responsible for the sameness:

ensure_loaded(Path) :- 
    absolute_file_name(Path, AbsPath),
    \+ visited(AbsPath), !,
    assertz(visited(AbsPath)),
    include(Path).
ensure_loaded(_).

But a challenge can be to have visited/1 automatically flushed
sometimes, so as to regain re-consult semantics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants