Replies: 4 comments 12 replies
-
If you would like I can implement PoC as part of #2602, by introduction of a simple list of excluded terms, but I expect way too many false positives, because a lot of code uses those constructs correctly. Later I think it can go even further then simply looking for terms. For example if left argument of |
Beta Was this translation helpful? Give feedback.
-
This is a highly desirable venture, but there are many obstacles in the way. First, it is necessary to precisely define what the goal is. My attempt is just such a definition but not a concrete implementation. Just think of number 7 ( Then, there is the question what algebraic properties a predicate must hold. Externally (that it behaves like a real relation) but (for some) also internally (that it can be generalized or specialized). Clearly, more than one notion of purity will be needed. Then, there is goal expansion which blurs those notions once again. Think of Here is a slightly less ambitious task, that is very much related and still non-trivial: Identify programs that can run on any conforming DCG implementation. That is, where all uses of non-terminals are via |
Beta Was this translation helpful? Give feedback.
-
Are these impure constructs used in length(Xs0, N) :-
'$skip_max_list'(M, N, Xs0,Xs),
!,
( Xs == [] -> N = M
; nonvar(Xs) -> var(N), Xs = [_|_], resource_error(finite_memory,length/2)
; nonvar(N) -> R is N-M, length_rundown(Xs, R)
; N == Xs -> failingvarskip(Xs), resource_error(finite_memory,length/2)
; length_addendum(Xs, N, M)
).
length(_, N) :-
integer(N), !,
domain_error(not_less_than_zero, N, length/2).
length(_, N) :-
type_error(integer, N, length/2).
%% reverse(?Xs, ?Ys).
%
% Xs is the Ys list in reverse order
%
% ?- reverse([1,2,3], [3,2,1]).
% true.
%
reverse(Xs, Ys) :-
( nonvar(Xs) -> reverse(Xs, Ys, [], Xs)
; reverse(Ys, Xs, [], Ys)
).
reverse([], [], YsRev, YsRev).
reverse([_|Xs], [Y1|Ys], YsPreludeRev, Xss) :-
reverse(Xs, Ys, [Y1|YsPreludeRev], Xss).
|
Beta Was this translation helpful? Give feedback.
-
My idea was to deduce safe mode declarations for any given predicate and add them to internal database for future reference. For example when during compilation I discover a fact: |
Beta Was this translation helpful? Give feedback.
-
Given a predicate in a Prolog program, I would like to identify any use it makes — whether direct or indirect — of impure constructs. So, build something like a call graph with a focus on impure leaves. Presumably, some kind of meta-interpretation would be required? Initially, I could be happy with manually 'whitelisting' certain library predicates (e.g.,
reif:if_/3
) known to use constructs such as(->)/2
safely. But in conjunction with such a facility, it might be nice to be able to annotate code itself ... or even reason automatically about it to identify where impure constructs may be granted a special dispensation.Beta Was this translation helpful? Give feedback.
All reactions