Efficient findall based meta-programming

BinProlog's findall/3 is so efficient that you can afford (with some care) to use it instead of explicit (and more painful) first-order programs as in:

% maplist with findall
maplist(Closure,Is,Os):-
  Closure=..L1,
  det_append(L1,[I,O],L2),
  P=..L2,
  findall(O,map1(P,I,Is),Os).

map1(P,I,Is):-member(I,Is),P.

This can be used as follows:

?- maplist(+(1),[10,20,30],T).
=> T=[11,21,31]

Note that constructing Closure only once (although this may not be in any Prolog text-book!) is more efficient than doing it at each step.

The predicate gc_call(Goal) defined in the file lib.pl executes Goal in minimal space. It is explained in the Craft of Prolog by R.A. O'Keefe, MIT Press. Do not hesitate to use it. BinProlog offers a very fast, heap-oriented findall, so you can afford to use gc_call. In good hands, it is probably faster than using assert/retract or the usual mark-and-sweep garbage collector of other implementations.