Skip to content

Monotonic predicate rewrite collect_vars #2542

Closed Answered by jjtolton
jjtolton asked this question in Q&A
Discussion options

You must be logged in to vote

@UWN sometimes I wonder if you get tired of answering the same question over and over again 🙄

I reviewed my notes, found your previous answer, combined it with @bakaq 's answer, and it solved many of the problems in the code I'm working.

collect_vars([],[]).
collect_vars([X/V|Rest], Vars) :-
        functor(X, F, _),
        if_(F=persist, Vars=NonPersistVars, Vars=[V|NonPersistVars]),
        collect_vars(Rest,NonPersistVars).

@triska also already answered this question in his video essay on Writing Prolog Code. The functor part of it really just made me forget everything, apparently!

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@jjtolton
Comment options

@bakaq
Comment options

@UWN
Comment options

@jjtolton
Comment options

@UWN
Comment options

Answer selected by jjtolton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants