I'm trying to implement a Scheme-like map function, i.e.
map([X1, X2, ..], Fun) ->[Fun(X1), Fun(X2), ...]
I wrote this code:
map([], Fun, []).
map([H|T], Fun, [HO|TO]) :- call(Fun, H, HO), map(T,F,TO).
Now, looking at this run:
?- map([1,2,3], plus(1), X).
X = [2, 3, 4] ;
X = [2, 3, 4] ;
X = [2, 3, 4] ;
X = [2, 3, 4] ;
ERROR: map/3: Arguments are not sufficiently instantiated
Exception: (9) map([3], _G380, _G351) ?
- How can I make it stop after the first solution provided?
- How can I trace it?If i use
traceit stop the execution after the first solution.
SWI-Prolog version 5.10.4 for i386maplistpredicate that does exactly what you want.