I started with prolog and it is hard. It really is!
Here I found a portable "IDE" http://portableapps.com/apps/ development/swi-prolog_ portable and here a video how to use it: https://www.youtube.com/watch? v=6Dh7eux76a8 .
I created a test project to summarize a list of numbers:
File > Edit > [select a file with following content: *.pl]
sumOfItems([], 0).
sumOfItems([H | T], Output) :-
sumOfItems(T, OutputInner),
Output is H + OutputInner.
sumOfItems([H | T], Output) :-
sumOfItems(T, OutputInner),
Output is H + OutputInner.
File > Consult > [select same file]
1 ?- sumOfItems([1,2,3,4,5],X).
X = 15.
X = 15.
... from now on changes to the file are taken over if they were compiled.
To check that I added the following function and compiled:
avgOfItems([H], Result) :-
Result is H.
avgOfItems([H|T], Result) :-
avgOfItems(T, ResultInner),
Result is (H + ResultInner)/2.
avgOfItems was callable...
kind regards,
Daniel
No comments:
Post a Comment