?- set_prolog_flag(toplevel_print_factorized, true), set_prolog_flag(toplevel_print_anon,true),set_prolog_flag(toplevel_mode,recursive). true.
?- T = nice(N), ( N = world, nb_linkval(myvar, T), fail ; nb_getval(myvar, V), writeln(V) ). nice(_5314) T = V, V = nice(N).
If someone doesn't mind the speed difference of duplicate_term/2 .
?- T = nice(N), ( N = world, nb_setval(myvar, T), fail ; nb_getval(myvar, V), writeln(V) ). nice(world) T = nice(N), V = nice(world).
This may be used to comprehend the values of a variables before the failure
?- use_module(library(clpfd)). true. ?- T = nice(N), ( N = my_world(A,B), B=10, (B#= A//2) , nb_setval(myvar, T), fail ; nb_getval(myvar, V), writeln(T --> V) ). nice(_3572)-->nice(my_world(_5714,10)) T = nice(N), V = nice(my_world(_6088, 10)), _6088 in 20..21.