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

Checking if a predicate exists within a specific module #389

Closed
guregu opened this issue Nov 13, 2023 · 8 comments
Closed

Checking if a predicate exists within a specific module #389

guregu opened this issue Nov 13, 2023 · 8 comments

Comments

@guregu
Copy link
Contributor

guregu commented Nov 13, 2023

Trealla's predicate lookup will scan all loaded modules as fallback, but is it possible to do a stricter check?

% foo.pl
:- module(foo, []).

is_foo.
% bar.pl
:- module(bar, []).

not_foo.
$ tpl foo bar
?- foo:current_predicate(not_foo/0).
   true. % is there some check that makes this false?

I played around with hacking search_predicate to only do the global search when q->st.m == q->pl->user_m for current_predicate/1 and it seems to work, but I have a feeling it might break something :-)

My use case is that I have a bunch of modules that may or may not define the same unexported predicates (something like entity definitions for a CRUD app), and I'd like to check if a particular module defines one, basically a crappy version of Logtalk protocols.

@infradig
Copy link
Contributor

infradig commented Nov 13, 2023 via email

@infradig
Copy link
Contributor

infradig commented Nov 14, 2023

There's still work to do but as it currently stands...

~/trealla (devel) $ cat foo.pl
:- module(foo, [is_foo/0]).
is_foo.
private_foo.
~/trealla (devel) $ tpl foo
Trealla Prolog (c) Infradig 2020-2023, v2.30.2-dirty
?- current_predicate(is_foo/0).
false. % WRONG
?- current_predicate(foo:is_foo/0).
true.
?- foo:current_predicate(is_foo/0).
true.
?- bar:current_predicate(is_foo/0).
false. % WRONG, should be exception?
?- current_predicate(bar:is_foo/0).
false.
?-

@guregu
Copy link
Contributor Author

guregu commented Nov 14, 2023

Awesome, thank you. I'll play around with it tonight.

@guregu
Copy link
Contributor Author

guregu commented Nov 14, 2023

Tried it out a bit and it looks good, thanks!

@pmoura
Copy link

pmoura commented Dec 12, 2023

My use case is that I have a bunch of modules that may or may not define the same unexported predicates (something like entity definitions for a CRUD app), and I'd like to check if a particular module defines one, basically a crappy version of Logtalk protocols.

I'm curious. Prolog modules are an evolutionary dead-end. Why try hacks around modules and spend time on crappy versions of Logtalk features when Logtalk fully supports Trealla Prolog?

@guregu
Copy link
Contributor Author

guregu commented Dec 12, 2023

My use case is that I have a bunch of modules that may or may not define the same unexported predicates (something like entity definitions for a CRUD app), and I'd like to check if a particular module defines one, basically a crappy version of Logtalk protocols.

I'm curious. Prolog modules are an evolutionary dead-end. Why try hacks around modules and spend time on crappy versions of Logtalk features when Logtalk fully supports Trealla Prolog?

No good reason, really. Part of it is trying to understand (and improve) quirks in Trealla. Part of it is because I don't have a good way of distributing Logtalk-based programs for browsers yet (this is no fault of Logtalk). I made an issue in trealla-js, let me know if you have any ideas: guregu/trealla-js#26

@infradig
Copy link
Contributor

I'm closing this.

@guregu
Copy link
Contributor Author

guregu commented Dec 12, 2023

Thanks @infradig!

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

3 participants