lambdaprologmeta-predicate

is it possible to use maplist/3 with 'anonymous' predicate?


What I wish to achieve with maplist/3 could for example be following pseudo code:

maplist(
   lambda X: Z/Y=X, to_lower(Z,LC), char_code(L,LC), return L/Y,
   ['A'/42, 'B'/500],
   Res).
Res = ['a'/42, 'b'/500]

I know that it is possible to write for example

maplist(plus(1), [1,2,3,4], Res).
Res = [2,3,4,5].

So I could just define the pseudocode lambda X: Z/Y=X, to_lower(Z,LC), char_code(L,LC), return L/Y as a normal predicate and use this predicate in the maplist...

However, I am curious if it is possible to do this without creating a whole new predicate?

The reason why I want to do it this way, is because I feel it is more natural to read, rather than jumping around in the code to find the predicate


Solution

  • See library(lambda)

    ?- maplist(\ (Z/Y)^(L/Y)^ ( char_code(Z,ZC),
                                to_lower(ZC,LC),
                                char_code(L,LC) ), ['A'/42, 'B'/500], Res).
       Res = [a/42, b/500].