For https://www.reddit.com/r/prolog/comments/wh6w01/clarification_of_how_flashlight_backtracking_works/ I wrote this unusual code:
member_flash(Elem, Lst) :-
bagof(Elem, member(Elem, Lst), Elems),
member(Elem, Elems).
How/why is the following query in swi-prolog 8.4.3 succeeding without a choicepoint? It is of course not using memberchk/2
?- member_flash(3, [1,2,3,1,2]).
true.
Interactively, the equivalent code does leave a choicepoint:
?- Lst = [1,2,3,1,2], bagof(Elem, member(Elem, Lst), Elems), member(3, Elems).
Lst = Elems, Elems = [1,2,3,1,2] ;
false.