Skip to content

Instantly share code, notes, and snippets.

@hutchison
Created June 7, 2016 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hutchison/45aa6748e64fe9df0a6115999bd771b6 to your computer and use it in GitHub Desktop.
Save hutchison/45aa6748e64fe9df0a6115999bd771b6 to your computer and use it in GitHub Desktop.
% vim:set noet sts=0 sw=8 ts=8 ft=prolog:
:- [hauptstadt].
hilfe :-
write('Anfragen mit:'), nl,
tab(3), write('?- findeHauptstadt.'), nl,
write('Sichern der aktuellen Daten mit:'), nl,
tab(3), write('?- speichern.'), nl.
findeHauptstadt :-
write('Geben Sie das Land ein: '),
read(Land),
(
hauptstadt(Land, Hauptstadt) -> (
write('Die Hauptstadt ist: '),
write(Hauptstadt)
); (
write('Die Hauptstadt konnte nicht gefunden werden.'), nl,
write('Bitte geben Sie sie ein:'), nl,
read(Hauptstadt),
assertz(hauptstadt(Land, Hauptstadt))
)
).
speichern :-
open('hauptstadt.pl', write, Stream),
write(Stream, ':- dynamic hauptstadt/2.\n\n'),
forall(
hauptstadt(Land, Hauptstadt),
format(Stream, "hauptstadt('~w', '~w').\n", [Land, Hauptstadt])
),
close(Stream).
:- dynamic hauptstadt/2.
hauptstadt('Deutschland', 'Berlin').
hauptstadt('Frankreich', 'Paris').
hauptstadt('Schweden', 'Stockholm').
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment