i'm studying prolog and I have to creat a program that returns the addition of numbers (in a list), that are smaller than a given number. I have this..
additionsmaller([X|XS],K,R):-X>K, additionsmaller(XS,K,R).
additionsmaller([X|XS],K,R):-X<K, additionsmaller(XS,K,T), R is T + X.
additionsmaller([X],K,X):-X<K.
additionsmaller([X],K,0):-K<X.
I expect for example:
additionsmaller([1,2,3,4,2],4,R).
R=8
But it give me false.
I'm using this https://swish.swi-prolog.org
What can I do to fix this? what is wrong with my code?