How transform data?

I’m using: SWI-Prolog version 8.41

I want the code to: print out: [f101, f201, f202] ( the cumulated items of r1 and r2 )

But what I’m getting is: nothing yet

My code template looks like this:

masterdata(X) :- X = [
    (r1, [f101]),
    (r2, [f201,f202]),
    (r3, [f301])  ]. 
transform(Rs, Masterdata, Fs) :-

test :- 
  transform([r1,r2], Masterdata, Fs),
  write(Fs). % [f101, f201, f202]

I’ve got no clue yet how I could start to find the items of r1 and r2 in the master data and combine them to a list in the form [f101, f201, f202].
Any help is appreciated. Where could I start with?

Solving old style:

transform(Rs, Masterdata, Fs) :-
    findall(Fs, (member(R,Rs),member((R,Fs),Masterdata)), LFs),

This yields

?- test.

… thanks! :slight_smile:

You’re welcome!

1 Like