I have a hard time understanding this application of zipwith in Prolog and wondered if someone gets it. I already have an idea of what functor does, but I don't see how it applies in that case. I vaguely think that the two arg
place arg no 1 and arg no 2 of CL into A
and B
, but they aren't used after that. Here is the predicate:
zipWith( _, [], [], [] ).
zipWith( OP, [A | AS], [B | BS], [CL | RS] ) :-
functor( CL, OP, 2 ),
arg( 1, CL, A ),
arg( 2, CL, B ),
zipWith( OP, AS, BS, RS ).
and here is an example of the use of this predicate:
| ?- zipWith( F, L1, L2, [b(w, w), b(f, g)] ).
F = b,
L1 = [w,f],
L2 = [w,g] ?yes