Maplist using a lambda on a lists of dicts doesn't work as expected

This has come up before and actually just bit me the other day! You can see what’s happening if you try doing listing(doesnt/1):

doesnt(L) :-
    '.'(A, b, C),
    maplist([A, B]>>(B=C),
            [#{a:1, b:2}, #{a:3, b:4}],
            L).

What’s happening here is that the expansion of the dot-syntax to look up the dictionary gets hoisted outside of the lambda, so it happens once at the beginning of the predicate, not each iteration through the lambda.

1 Like