This concept uses the foreach keyword in two different ways. The first is used to scan an existing list L, the second is used to construct a list K as the result of the operation.
:-mode transformation(+,-). transformation(L,K):- (foreach(X,L), foreach(Y,K) do q(X,Y) ).
:-mode convert_to_router_mib(+,-,-). convert_to_router_mib(L,K,Router):- (foreach(router_mib_data with [router:Router, time:Time, tcp_segm_in:A, tcp_segm_out:B, udp_datagram_in:C, udp_datagram_out:D],L), foreach(t(Time,router_mib with [tcp_segm_in:A, tcp_segm_out:B, udp_datagram_in:C, udp_datagram_out:D]),K), param(Router) do true ).In this example the transformation is completely handled by matching arguments in the foreach statements. We use the predicate true for an empty loop body.
Figuring out what is happening with the variable Router is left as an exercise for the advanced reader.