Loading 2.4.1_6.pl 0 → 100644 +40 −0 Original line number Diff line number Diff line % nacteni: /* ['2.4.1_6.pl']. */ append([],L,L). append([H|T1],L2,[H|T]) :- append(T1,L2,T). % demonstracni vypis % abychom se vyhli varovanim "Redefined static procedure ..." :- dynamic write_all_X/3, start/0. write_all_X(Goal,X,Name):- call(Goal),write(' '),write(Name),write(' = '),write(X),nl,fail. write_all_X(_,_,_). write_all_XY(Goal,X,XName,Y,YName):- call(Goal),write(' '),write(XName),write(' = '),write(X), write(' '),write(YName),write(' = '),write(Y), nl, fail. write_all_XY(_,_,_,_,_). start:- write('Prace se seznamy - append'),nl, write('-------------------------------'),nl, nl, write('vicesmernost predikatu append:'),nl, write('Vysledek volani "append([a,b],[c,d],L)":'),nl, write_all_X(append([a,b],[c,d],L), L, 'L'),nl, write('Vysledek volani "append(X,[c,d],[a,b,c,d ]).":'),nl, write_all_X(append(X,[c,d],[a,b,c,d ]), X, 'X'),nl, write('Vysledek volani "append(X,Y,[a,b,c])":'),nl, write_all_XY(append(X,Y,[a,b,c]), X, 'X', Y, 'Y'),nl. ?-start. :- retractall(write_all_X/3). :- retractall(start/0). 2.4.1_6.py 0 → 100644 +37 −0 Original line number Diff line number Diff line #!/usr/bin/env python # encoding=utf-8 (pep 0263) def append(xs, ys): if not xs: return ys else: return [xs[0]] + append(xs[1:], ys) def append_anyXs(ys, zs): if ys == zs: return [] else: if zs: return [zs[0]] + append_anyXs(ys, zs[1:]) else: raise ValueError("ys neni sufixem zs") def append_anyXsYs(zs): yield ([], zs) if zs: for xs, ys in append_anyXsYs(zs[1:]): yield ([zs[0]] + xs, ys) # demonstracni vypis if __name__ == "__main__": print("Prace se seznamy - append") print("-------------------------------\n") print("vicesmerne implementace funkce append:\n") print("Vysledek volani append(['a', 'b'], ['c', 'd']): %s\n" % \ append(['a', 'b'], ['c', 'd'])) print("Vysledek volani append_anyXs(['c', 'd'], ['a', 'b', 'c', 'd']): %s\n" % \ append_anyXs(['c', 'd'], ['a', 'b', 'c', 'd'])) print("Vysledek volani append_anyXsYs(['a', 'b', 'c']): %s\n" % \ list(append_anyXsYs(['a', 'b', 'c']))) Loading
2.4.1_6.pl 0 → 100644 +40 −0 Original line number Diff line number Diff line % nacteni: /* ['2.4.1_6.pl']. */ append([],L,L). append([H|T1],L2,[H|T]) :- append(T1,L2,T). % demonstracni vypis % abychom se vyhli varovanim "Redefined static procedure ..." :- dynamic write_all_X/3, start/0. write_all_X(Goal,X,Name):- call(Goal),write(' '),write(Name),write(' = '),write(X),nl,fail. write_all_X(_,_,_). write_all_XY(Goal,X,XName,Y,YName):- call(Goal),write(' '),write(XName),write(' = '),write(X), write(' '),write(YName),write(' = '),write(Y), nl, fail. write_all_XY(_,_,_,_,_). start:- write('Prace se seznamy - append'),nl, write('-------------------------------'),nl, nl, write('vicesmernost predikatu append:'),nl, write('Vysledek volani "append([a,b],[c,d],L)":'),nl, write_all_X(append([a,b],[c,d],L), L, 'L'),nl, write('Vysledek volani "append(X,[c,d],[a,b,c,d ]).":'),nl, write_all_X(append(X,[c,d],[a,b,c,d ]), X, 'X'),nl, write('Vysledek volani "append(X,Y,[a,b,c])":'),nl, write_all_XY(append(X,Y,[a,b,c]), X, 'X', Y, 'Y'),nl. ?-start. :- retractall(write_all_X/3). :- retractall(start/0).
2.4.1_6.py 0 → 100644 +37 −0 Original line number Diff line number Diff line #!/usr/bin/env python # encoding=utf-8 (pep 0263) def append(xs, ys): if not xs: return ys else: return [xs[0]] + append(xs[1:], ys) def append_anyXs(ys, zs): if ys == zs: return [] else: if zs: return [zs[0]] + append_anyXs(ys, zs[1:]) else: raise ValueError("ys neni sufixem zs") def append_anyXsYs(zs): yield ([], zs) if zs: for xs, ys in append_anyXsYs(zs[1:]): yield ([zs[0]] + xs, ys) # demonstracni vypis if __name__ == "__main__": print("Prace se seznamy - append") print("-------------------------------\n") print("vicesmerne implementace funkce append:\n") print("Vysledek volani append(['a', 'b'], ['c', 'd']): %s\n" % \ append(['a', 'b'], ['c', 'd'])) print("Vysledek volani append_anyXs(['c', 'd'], ['a', 'b', 'c', 'd']): %s\n" % \ append_anyXs(['c', 'd'], ['a', 'b', 'c', 'd'])) print("Vysledek volani append_anyXsYs(['a', 'b', 'c']): %s\n" % \ list(append_anyXsYs(['a', 'b', 'c'])))