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

Fine-grained multifile interfaces proposal #2674

Closed
wants to merge 1 commit into from

Conversation

hurufu
Copy link
Contributor

@hurufu hurufu commented Dec 3, 2024

Recently I was thinking what if I have a module that defines a multifile predicate, but I want some level of control on how it can be extended. For example I may want to allow heads of new clauses only when they are unifiable with my template.

Let's say I have the following predicate in my module:

:- module(greeting, [hello/2]).
:- multifile(hello/2).
hello(admin, "Hello admin").

I want others to import my module and being able to add their own hello/2, but with additional constraint: I want to restrict them to greet only user and not admin or anything else. So the following (new) clause should be allowed greeting:hello(user, "Hi"), but greeting:hello(root, "Hi") – shouldn't.

In my proposal you need to define an "interface":

hello(user, _) :- 0.

Which will be replaced during term expansion with a special predicate that will validate other clauses.

I'm open for comments and opinions.

@hurufu hurufu marked this pull request as draft December 3, 2024 07:26
@triska
Copy link
Contributor

triska commented Dec 3, 2024

Is this (or should this be) limited to facts?

For example, what about the following clauses:

hello(U, "Hello admin") :- U = root.
hello(U, "Hello")       :- U = user.

Are they allowed/disallowed?

Or what about:

hello(U, "Hello") :-
        (   proof_of_twin_prime_conjecture_exists ->
            U = root
        ;   U = user
        ).    

In general, the value of U may not be decidable. For instance:

hello(U, "Hello", TM) :-
        (   turing_machine_halts(TM) ->
            U = root
        ;   U = user
        ).

@hurufu
Copy link
Contributor Author

hurufu commented Dec 3, 2024

I've completely forgot to think that in general it is a much harder problem. Thanks for pointing this out. This means that it is much better if you use multifile predicate to implement wrapper and do some sanity checks in runtime. Like greet :- hello(user, X), write(X), nl.. This will still select correct predicate, and wouldn't rely on some compile-time checks. I think it is Ok to close this RFC :).

@hurufu hurufu closed this Dec 4, 2024
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

Successfully merging this pull request may close these issues.

2 participants