a(S,S2) :-concat([S, 'a'], S2). b(S,S2) :-concat([S, 'b'], S2). c(S,S2) :-concat([S, 'c'], S2). s:-s(S), write(S), nl. t:-t(T), write(T), nl. u:-u(U), write(U), nl. s(S):-s('', S). s(S0,S):-c(S0,S) ; a(S0,S1),s(S1,S2),b(S2,S). t(T):-t('',T). t(T0,T):-a(T0,T1), c(T1,T) ; a(T0,T1),t(T1,T). u(U):-u('',U). u(U0,U):-c(U0,U) ; a(U0,U1),b(U1,U2),b(U2,U3),u(U3,U) ; a(U0,U1),b(U1,U2),u(U2,U3),b(U3,U) ; a(U0,U1),u(U1,U2),b(U2,U3),b(U3,U) ; u(U0,U1),a(U1,U2),b(U1,U2),b(U3,U). :- write('Input s(S), nl? , t(T)?, or u(U)? to generate strings'). :- write(' But prolog won't generate all the U strings....'), nl.