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

Handle module scoping in library(lambda) #2543

Closed
wants to merge 2 commits into from

Conversation

bakaq
Copy link
Contributor

@bakaq bakaq commented Sep 8, 2024

Closes #2255.

This makes library(lambda) not terrible to use when having to deal with multiple module scopes. Example of functionality:

%% Contents of a.pl
:- use_module(library(lambda)).

:- use_module(b).

p.

make_goal_a(\p).
%% Contents of b.pl
:- module(b, [
    make_goal_b_raw/1,
    make_goal_b_scoped/1,
    make_goal_b_scoped_alt/1
]).

:- use_module(library(lambda)).

% Private to module b
q.

make_goal_b_raw(\q).

% Giving the call to private q/0 an explicit scope
make_goal_b_scoped(\(b:q)).

% Giving the entire lambda a scope
make_goal_b_scoped_alt(b:(\q)).
% All of the following error in current master!
?- use_module(a).
   true.
?- make_goal_a(G), call(G).
   G = \p.
?- make_goal_b_raw(G), call(G).
   error(existence_error(procedure,q/0),q/0).
?- make_goal_b_raw(G), call(b:G).
   G = \q.
?- make_goal_b_scoped(G), call(G).
   G = \ (b:q).
?- make_goal_b_scoped_alt(G), call(G).
   G = b: \q.

EDIT: This does not fix whatever the hell is happening in #2255 (comment), but just sidesteps it. That is probably related to module scope explicitation in goal expansion or something like that.

@UWN
Copy link

UWN commented Sep 8, 2024

Note that this works in SICStus without changes. So it seems this is an ad hoc change that might only delay actual adaptations in the module system in general.

@bakaq
Copy link
Contributor Author

bakaq commented Sep 8, 2024

Note that this works in SICStus without changes. So it seems this is an ad hoc change that might only delay actual adaptations in the module system in general.

Probably, but every time I try to do anything remotely interesting with library(lambda) (I was trying to make a "IO monad"-like library) this blocks me from going much deeper, and the underlying problem seems much harder to fix1. It's a small diff (ignoring tests it's +15-5), we can always revert later if this turns out unnecessary.

If I find out how to fix the underlying issue, then I will close this if it's not already merged, and revert this if it was.

Footnotes

  1. And just following SICStus here may even be something we want to avoid or improve upon (Unclear semantics of module-qualified control constructs #2502 for example).

@UWN
Copy link

UWN commented Sep 8, 2024

SICStus is the only stable reference. And unless someone comes up with a clean semantics, it is all we have. Note that SWI for example did more or less patch the SICStus modules into an existing different system (with module_transparent declarations), and the result is that many things broke (like my first sketchy implementation of goal expansion in reif).

@bakaq
Copy link
Contributor Author

bakaq commented Sep 8, 2024

SICStus is the only stable reference. And unless someone comes up with a clean semantics, it is all we have.

That is a good point. My problem with this is that I don't have access to SICStus (too expensive and I don't want to burn my trial period just yet) so I don't have a good way to test how it works. Would you be willing to run some examples that I send through e-mail so that I can make a decent reference test suite?

@bakaq
Copy link
Contributor Author

bakaq commented Sep 10, 2024

I think @hurufu's work in hurufu#1 supersedes this. Closing (for now).

@bakaq
Copy link
Contributor Author

bakaq commented Sep 11, 2024

For now, a workaround is to wrap the goal to (^)/N, (/)/N and (+/)/N in (user:Goal). It's kinda inconvenient having to type that everywhere but seems to work.

@UWN
Copy link

UWN commented Sep 12, 2024

Just a naive question: If you propose to add user: then you are privileging the user module. So your approach will not work anywhere else. Or: you are using explicit qualification everywhere. I have not seen this problem in SICStus, so then it must be resolvable differently.

@bakaq
Copy link
Contributor Author

bakaq commented Sep 12, 2024

I am using explicit qualification everywhere, because that is what works currently. Could you run at least the example queries in the OP in SICStus so that I know more or less what is expected here? From what you are saying maybe even make_goal_b_raw(G), call(G). succeeds and that would be very nice indeed.

@UWN
Copy link

UWN commented Sep 12, 2024

(Please do read my mail of 2024-09-08)

| ?- asserta(library_directory('.')).
yes
| ?- use_module(a).
% compiling /tmp/a.pl...
%  compiling /tmp/lambda.pl...
%   module lambda imported into user
%  compiled /tmp/lambda.pl in module lambda, 476 msec 770576 bytes
%  compiling /tmp/b.pl...
%   module b imported into user
%   module lambda imported into b
%  compiled /tmp/b.pl in module b, 4 msec 9616 bytes
% compiled /tmp/a.pl in module user, 520 msec 846816 bytes
* /tmp/a.pl is not a module file
yes
| ?- make_goal_a(G), call(G).
G = \p ? ;
no
| ?- make_goal_b_raw(G), call(G).
! Existence error in user:q/0
! procedure user:q/0 does not exist
! goal:  user:q
| ?- make_goal_b_raw(G), call(b:G).
G = \q ? ;
no
| ?- make_goal_b_scoped(G), call(G).
G = \ (b:q) ? ;
no
| ?- make_goal_b_scoped_alt(G), call(G).
G = b: \q ? ;
no

@bakaq
Copy link
Contributor Author

bakaq commented Sep 12, 2024

Oh, you sent me an email? Did you send it to my old institutional account (usp.br)? That account is now deleted for more than a month because I'm not longer affiliated with that university, I sent you an email warning about that before deletion. Please send new emails to the email I have currently listed in my Github profile, it's a stable address that I own.

@bakaq bakaq deleted the lambda_modules branch October 13, 2024 18:34
@bakaq bakaq restored the lambda_modules branch October 13, 2024 18:34
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 in call/1 confused predicate calls
2 participants