## How to Average in Prolog

If I had to average a list of numbers, I would probably do it like this: averagelist(List, Avg) :- length(List, N), sumlist(List, Sum), Avg is Sum / N. This resembles the actual mathematical definition. Then you could just make a list of numbers and average that. @lurker is right, this is a terrible way to go, but it would work: average(N, Avg) :- findall(I, between(1, N, I), Is), averagelist(Is, Avg). »