/* Find (and run) all go./0-n predicates in Picat. The predicates generated by bp.current_predicate that we are interested in are prepended by "e$$glb$$", e.g. go/0 is represented as the atom "e$$glb$$go / 0" This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util, v3_utils. main => go. go ?=> find_go(P), println(P), fail, nl. go => true. go2 ?=> All = findall(P, find_go(P)), println(All), nl. go2 => true. go3 ?=> println("Testing go3 which call all go*/0-n predicates"), All = findall(P, find_go(P)), foreach(P in All) atom_chars(Pred,P), println(pred=Pred), if Pred == go3 then println("This is go3 which is skipped so we don't loop infinitely!") else call(Pred) end end, nl. go3 => true. % % Find - and run - all predicates which starts with % the string Base, default "go". % Note: This only find predicates without arguments % % The predicates generated by bp.current_predicate that we are % interested in are prepended by "e$$glb$$", e.g. % go/0 is represented as the atom % "e$$glb$$go / 0" % /* % First approach run_pred(Base,P) :- bp.current_predicate(X), Y=X.to_string, % find(Y,"e$$glb$$" ++ Base,_,_), once(append("e$$glb$$",P1,Y)), once(append(P," /",_,P1)). */ % Find and run all go* /0-n predicates. find_go(P) :- run_pred("go",0,P). run_pred(Base,P) :- run_pred(Base,0,P). run_pred(Base,Arity, P) :- current_predicate(X), Y=X.to_string, % X is an atom. Convert to string so we can use find/4 find(Y,"e$$glb$$" ++ Base,_,_), once(append("e$$glb$$",P," / " ++ Arity.to_string,Y)).