diff --git a/assignment5/.gitignore b/assignment5/.gitignore new file mode 100644 index 0000000..caf7d82 --- /dev/null +++ b/assignment5/.gitignore @@ -0,0 +1 @@ +ass5.pdf diff --git a/assignment5/Makefile b/assignment5/Makefile new file mode 100644 index 0000000..bad7961 --- /dev/null +++ b/assignment5/Makefile @@ -0,0 +1,9 @@ +PROLOG = swipl +.PHONY: run clean +all: run/main.pl +run/%: + @$(PROLOG) -f $* -t halt -q +consult/%: + @$(PROLOG) -f $* -q +clean: + rm -f *.qlf diff --git a/assignment5/test.pl b/assignment5/test.pl new file mode 100644 index 0000000..c7edff7 --- /dev/null +++ b/assignment5/test.pl @@ -0,0 +1,19 @@ +parent(tom, bob). +parent(tom, liz). +parent(bob, ann). +parent(bob, pat). +parent(pat, jim). + +grandparent(X, Z) :- parent(X, Y), parent(Y, Z). +ancestor(X, Y) :- parent(X, Y). +ancestor(X, Y) :- parent(X, Z), ancestor(Z, Y). + +:- initialization(main). + +main :- + write('Grandparents of jim: '), + findall(X, grandparent(X, jim), Grandparents), + write(Grandparents), nl, + write('Ancestors of jim: '), + findall(X, ancestor(X, jim), Ancestors), + write(Ancestors), nl. diff --git a/flake.nix b/flake.nix index d89ca90..7f290e7 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ sbt scala scalafmt + swi-prolog ]; shellHook = '' echo "enjoy m*oz*art2"