Surprising Transformation for Dictionaries and Yall

I’m using: SWI-Prolog version 8.1.10 for x86_64-linux

The following code:

test(Included) :-
    Names = [a,b,c],
    Objects = [_{name: a}, _{name : f}, _{name : c}, _{name : g}],
    include({Names}/[Object]>>(memberchk(Object.name, Names)),
            Objects, Included).

Has a listing of:

test(E) :-
    A=[a, b, c],
    D=[_{name:a}, _{name:f}, _{name:c}, _{name:g}],
    '.'(B, name, C),
    include({A}/[B]>>memberchk(C, A), D, E).

This transformation should happen internal to the yall predicate or we are never going to find the dictionary!

1 Like

Yes. Functional expansion for meta arguments is still a bit of a mess. I’m working on a new code base for code expansion. This can be a nice test case. For now I’d use a helper predicate …

1 Like

BTW, I absolute love dictionaries. They are a huge advantage over having to have a structured term where all arguments are by position. This created enormous hassles in refactoring code in the past. Well done on the innovation!

2 Likes

I second the “huge advantage”. On the functional front, Clojure code for example is a lot of maps being passed around, read and completed as needed.

Unfortunately, this may not work well in Prolog. If you have a

predicate p(Dict) :- "do something to Dict, in particular, guard checks on Dict values"

then Prolog has nothing to index on regarding head arguments and performance will not be excellent.

1 Like