JanWielemaker / swi-erlang

Yes, Erlang in SWI-Prolog!
12 stars 1 forks source link

The pengines currently does not work with the src_* options. #5

Closed torbjornlager closed 6 years ago

torbjornlager commented 6 years ago

The pengines currently does not work with the src_* options. It seems that we somehow need to get the name of the module used for isolation into the right place, like below. But how to do that?

ask(Goal, Options, Self, Parent) :-
    option(template(Template), Options, Goal),
    option(limit(Limit), Options, 1),
    State = count(Limit),
    (   call_cleanup(findn0(State, Template, **Module**:Goal, Solutions, Error), Det=true),
        (   var(Error)
        ->  (   var(Det)
            ->  Parent ! success(Self, Solutions, true),
                receive({
                    pengine:next(Count) -> 
                        nb_setarg(1, State, Count),
                        fail;
                    pengine:stop ->
                        Parent ! stop(Self)  
                })
            ;   Parent ! success(Self, Solutions, false)
            )
        ;   Parent ! error(Self, Error)
        )
    ;   Parent ! failure(Self)
    ).
JanWielemaker commented 6 years ago

If ask/4 is successfully called in the process, adding a meta-predicate declaration as in

:- meta_predicate ask(0, +, +, +).

will probably do.

P.s. please keep Options as last argument.

torbjornlager commented 6 years ago

No, that didn't do it. It has the effect that the first arg of ask/4 gets bound to pengines:Goal.

JanWielemaker commented 6 years ago

The initial goal called from the spawn gets the right module context. From there on you must make sure not to loose that.

torbjornlager commented 6 years ago

Ok, thanks. I think I got it now.

torbjornlager commented 6 years ago

context_module/1 has to be declared safe in the sandbox for it to work also in the case of remote pengines.

JanWielemaker commented 6 years ago

You shouldn't need it. Use meta_predicate/1 declaration. Normally you can just pass on the qualified argument from there. In some extreme cases you match the Module:Term argument to pick up the module and reuse it in some other way.

torbjornlager commented 6 years ago

I'm afraid I don't quite get that. The initial goal called from the spawn (session/3) doesn't have a qualified argument. The ask/4 predicate is called later - too late, isn't it?

JanWielemaker commented 6 years ago

So, you must define session/3 as a meta-predicate as you want it to know its context. If there is no clear module-sensitve argument, just specify the most sensible argument as : and pick it up as Module:Term in the head of session/3.

torbjornlager commented 6 years ago

Aha, now I got it!