I decided to write a maplist type predicate that will be used to map a
function over a list and return the list of transformed values. I have
wanted this for a while now and I sat down and came up with this. It works
BUT I am not happy with it for reasons outlined below so any suggestions
etc. are welcome.
maplist2(In, X, Out) :-
transform_list(In, X, [], Out).
transform_list([], _, Acc, Final) :-
reverse(Acc, Final).
transform_list([E|Es], Xfn, Acc, Final) :-
Xform =.. [Xfn, E, Out],
call(Xform),
transform_list(Es, Xfn, [Out|Acc], Final).
For example, if I wanted to convert a string from lower case to upper case
I would have to use a list of atoms to satisfy lower_upper/2, that's not an
issue. The assumption for my maplist2 is that the transformer function has
arity 2 and the first paramter is the input and the second is the output.
What is the issue though is that lower_upper/2 works either way around and
if I wanted to convert a->'A' or 'A'->a then how would that work?
Haskell has sections and "flip"..is there a Prolog way to say that I want
to change the order of evaluation of a function if you catch my drift?
Thinking on my feet here, it would be the difference between currently
passing in:
lower_upper
and then in a cool world using
lower_upper(X,_)
or
lower_upper(_,X)
instead and "it" would know to replace "_" with the input parameter...I am
going to see what I can come up with!
Thanks,
Sean.
_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog