0

attempting to create a list comprehension. What I have here works in SWI Prolog, and also Jekejeke Prolog, but the [ <- ] operator fails in Yap. Unable to figure out why.

Had to create between/3, findall/3, and maplist/2 because they aren't part of Yap. I believe the three homemade predicates work properly (they do in Jekejeke Prolog).

Yap 6.2.2 seems unable to handle the [ <- ] operator. Gets a syntax error immediately preceding the operator.

DEFINE operators:

:- op(700, xfx, [ <- ]).
:- op(450, xfx, [ .. ]).
:- op(1100, yfx, [ & ]).

CREATE a template for list comprehension:

Vs <- M..N :-
    integer(M),
    integer(N),
    M =< N,
    betWeen(M, N, Vs).

Vs <- {Var & Dec & Pred} :-
    findAll(Var, mapList(call, [Dec, Pred]), Vs).

USE the template to create a list of primes from M through N, inclusive. Return the list as P.

primes(M, N, P) :- P <- { X & X <- M..N & prime(X) }.

END.

dogwood
  • 371
  • 2
  • 11
  • Cannot reproduce. Maybe you have some more ops defined? I stumbled across `betWeen` which should have `w` instead. – false May 26 '16 at 11:05

1 Answers1

0

Tried many things that didn't work, but when I moved my definitions for the predicates mapList/2, findAll/3, and betWeen/3 into the same module where the new operators are defined, it solved the problem.

Those three predicates are needed in Yap because, unlike SWI-Prolog, they are not supplied. Maybe they are in a library that I don't have.

dogwood
  • 371
  • 2
  • 11