[tutor] Update assignment

This commit is contained in:
tolauwae 2025-03-30 21:56:24 +02:00
parent 39c3af4ba5
commit ca687c0136
No known key found for this signature in database
GPG key ID: 20E068EB5B132116
18 changed files with 438 additions and 14 deletions

28
examples/meta/mib.pl Normal file
View file

@ -0,0 +1,28 @@
% Old mag steeds door New vervangen worden
mib(Old, New, Old, New).
% Een term blijft enkel behouden als het een attoom is
% (dat is, niet compound), en als het niet Old is
mib(Old, _, Term, Term) :-
atomic(Term),
Term \= Old.
% Voor een samengestelde Term
mib(Old, New, Pre, Post) :-
compound(Pre),
functor(Pre, F, N), % Pre heeft naam F en arriteit N
functor(Post, F, N), % Post is term met zelfde naam (F) en arriteit (N)
mib(N, Old, New, Pre, Post).
% Extra predicaat om de argumenten te vervangen van een samengestelde term
%
% N = het nr van het argument (strikt positief)
mib(0, _, _, _, _) :- !. % Argument 0 bestaat niet, als we hier komen zijn we klaar.
mib(N, Old, New, Pre, Post) :-
arg(N, Pre, ArgPre), % neem het N-de argument
mib(Old, New, ArgPre, ArgPost), % vertaal het
arg(N, Post, ArgPost), % unificeer het met het N-de argument van output
N1 is N-1,
mib(N1, Old, New, Pre, Post). % Herhaal voor argument N-1