i trying compute arithmetic calculations , store results in new list in prolog. function prototype goes follows:
calculation(list1, listoflists, resultlist) for first argument provide list, second argument list of lists , third result list. compute first argument list each list of list of lists , store result in resulting list. can tell me how can store results in resulting (empty) list?
with library lambda can write:
:- use_module(library(lambda)). :- use_module(library(clpfd)). calculation(l1, l2, compute, l) :- maplist([l2,compute] +\x^y^call(compute,l2, x, y), l1, l). % my_compute succeeds when r list of products % of numbers component of l number v my_compute(l, v, r) :- maplist(v +\x^y^maplist(v +\z^t^(t #= z * v), x, y), l, r). here example:
?- calculation([1,2,3], [[4,5],[6,7]], my_compute, zss). zss = [[[4, 5], [6, 7]], [[8, 10], [12, 14]], [[12, 15], [18, 21]]]. ?- zss = [[[4,5],[6,7]],[[8,10],[12,14]],[[12,15],[18,21]]], calculation(xs, [[4,5],[6,7]], my_compute, zss). xs = [1, 2, 3]. ?- zss = [[[4,5],[6,7]],[[8,10],[12,14]],[[12,15],[18,21]]], calculation([1,2,3], xss, my_compute, zss). xss = [[4, 5], [6, 7]].
Comments
Post a Comment