Skip to content

How to ignore variables in a Prolog query #2190

Answered by UWN
razetime asked this question in Q&A
Discussion options

You must be logged in to vote

Instead of explicitly ignoring some variables, you may just indicate the variables you are interested in:

?- use_module(library(lambda)).
   true.
?- B+\ ( member(A,[[1],[2]]), member(B,A) ).
   B = 1
;  B = 2.
?- [B,C]+\ ( member(A,[[1],[2]]), member(B,A), C = more ).
   B = 1, C = more
;  B = 2, C = more.

Note that suppressing the answers for named variables starting with an underscore collides with new variables in answers.

?- length(L,3).
   L = [_A,_B,_C].

This becomes a problem, if you want to paste back such answers into a further query.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by razetime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants