Skip to content

eliminating use of -> operator #1958

Answered by pmoura
mvolkmann asked this question in Q&A
Aug 9, 2023 · 8 comments · 15 replies
Discussion options

You must be logged in to vote

expecting to get FirstVar = Bar I instead get error(existence_error(procedure,var/2),var/2). This is of course because var/2 doesn't exist, but var/1 does. if_ is trying to pass two arguments to its first argument predicate instead of one. I don't know how to get if_ to work in this case.

You need to reify var/1:

$ scryer-prolog
?- use_module(library(reif)).
   true.
?- [user].
list_pred_first([], _, []).
list_pred_first([H|T], Pred, R) :-
    if_(call(Pred, H), R = H, list_pred_first(T, Pred, R)).

var(X, T) :- (var(X) -> T = true; T = false).

?- L = [foo, Bar, baz], list_pred_first(L, var, FirstVar).
   L = [foo,Bar,baz], Bar = FirstVar.
?- 

But note Ulrich's observations on var/1...

Replies: 8 comments 15 replies

Comment options

You must be logged in to vote
2 replies
@mvolkmann
Comment options

@triska
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@triska
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
10 replies
@mvolkmann
Comment options

@UWN
Comment options

@UWN
Comment options

@mvolkmann
Comment options

@UWN
Comment options

Comment options

You must be logged in to vote
2 replies
@mvolkmann
Comment options

@UWN
Comment options

Answer selected by mvolkmann
Comment options

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