Higher order metapredicates (Was: Lambda-like continuations)

View: New views
1 Messages — Rating Filter:   Alert me  

Higher order metapredicates (Was: Lambda-like continuations)

by Eckard Brauer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

nearly completely ignorant on how the internals of any Prolog system
work and maybe a very stupid point, but if not asked (and explained)
somewhere, I'll never understand:

I wonder if there were the possibility to make the following
expressions possible (referring Ulrich's posting on Lambda-like
continuations), and what the reasons for the potential impossibility
(or drawbacks, if possible at all) are:

(i) Ulrich's code:

:- meta_predicate ^(?,0,?).
:- meta_predicate ^(?,1,?,?).
:- meta_predicate ^(?,2,?,?,?).
:- meta_predicate ^(?,3,?,?,?,?).

changed to:

meta_meta_predicate(P) :-
        P =.. [^, ?, I, ? | L],
        length(L, I),
        :- meta_predicate P.

(ii) Ulrich's code again:

^(V1, Goal, V1) :- call(Goal).
^(V1, Goal, V1, V2) :- call(Goal, V2).
^(V1, Goal, V1, V2, V3) :- call(Goal, V2, V3).
^(V1, Goal, V1, V2, V3, V4) :- call(Goal, V2, V3, V4).
^(V1, Goal, V1, V2, V3, V4, V5) :- call(Goal, V2, V3, V4, V5).

changed to:

meta_call(P) :-
        P =.. [^, V1, Goal, V1 | L],
        CallGoal =.. [Goal | L],
        call(CallGoal).

and so on.

IMHO both would need changes in the compiler and I can't see the
consequences (compile time, runtime and semantics), but OTOH, wouldn't
it make handling variable number of arguments possible (there has
already been a discussion on "call/N - how much?"), what otherwise is
only possible using lists as arguments?

Compatibility is another point, of course.

Cheers,
Eckard
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog