Functional programming with arbitrary mappings

If you read the previous post, you probably asked yourselves a question, what happens if the predicates that represent functions are non-deterministic, i.e., return more than one possible value for a given set of arguments. As a result of this, combinator functions containing such mappings also become general mappings. Look at this new example func_002.prova:

% Demonstrate mappings that are not functions (based on non-deterministic values)

%%% use map to double the list elements POSSIBLY negating them: 8 solutions
:- solve(map([[plusminus,double],[1,2,3]],X)).

%%% Functional programming utils (result is always the last parameter)
%%% All functions are predicates with two parameters: Args and Result. 

map([_,[]],[]).
map([Fun,[A|As]],[B|Bs]) :-
	derive(Fun(A,B)),
	map([Fun,As],Bs).

%%% Test functions (result is always the last parameter)
%%% Multiple arguments and compound results are passed as lists 

double(X,XM) :-
	XM=2*X.

plusminus(X,X).
plusminus(X,XM) :-
	XM=-X.

So we double the list elements and apply a "function" plusminus that is non-deterministic. It is obvious that we have 2^3=8 solutions to the goal in this code, correspondng to each doubled element with plus or minus in front.