Skip to main content David Edelstein's Blog

🦙
🦙

prolog findall using nb_setarg/3

Published: 2011-10-04
dave@edelsteinautomotive.com
David Edelstein

##my findall/3

findall(Bindings, Code, ListOut) :-
  HoldNext=hold(ListOut), %store the tail of the difference list here
  (  Code,
     arg(1, HoldNext, Nxt), %var containing the hole to write to
     Nxt=[Bindings|NewNxt],
     nb_setarg(1,HoldNext, NewNxt),
     fail
  ;  arg(1, HoldNext, Nxt),
     Nxt=[]
  ).