1

Ok. This is the idea. I'll have a list (lets call it listA) something like [a0,a1,a2...] which are gameboard spaces for me to move (like in chess). I want to run a process on all of them (on a0, on a1, ...). This process will return a list of other spaces (when you run it on a0 it will return [b0,c0,..]) for each element in listA. I have to "return" a list with all the process(listA) outputs.

Hope I explained myself. PS. I've tried using my own ideas and with maplist but couldnt make it.

Diego Rivera
  • 403
  • 1
  • 5
  • 19
  • 2
    You are on the right track with `maplist/3`. First, focus on defining the relation between a *single* such position and its associated list, say as `position_list/2`. Once you have that, you can easily lift this to lists of such positions `Ps` with `maplist(position_list, Ps, Ls)` and obtain as `Ls` the lists of such associated lists, one for each element of `Ps`. You will find that limiting the definition to individual items will make your code simpler and easier to understand, and `maplist/3` is a good fit to lift this to lists. – mat Oct 15 '15 at 13:58
  • I've been trying to do a maplist (like the one in swi-prolog) for TurboProlog. Is there a equivalent of it in this prolog version? Or should I "create" it? – Diego Rivera Oct 15 '15 at 15:14
  • 2
    If your system does not ship with `maplist/3`, just write it yourself, using 3 lines of code. If your Prolog system supports `call/3` (ie., ideally), you define `maplist/3` like: `maplist(_, [], []). maplist(Goal, [L0|Ls0], [L|Ls]) :- call(Goal, L0, L), maplist(Goal Ls0, Ls).`, or some variation of this to benefit from first argument indexing. If `call/3` is not available, use `(=..)/2` etc. to build the goal dynamically and use `call/1` to call it. Thankfully, more and more systems provide `maplist/3` out of the box or in a library already. Maybe you can suggest this to the TurboProlog team. – mat Oct 15 '15 at 15:19
  • See [this](http://stackoverflow.com/a/6683502/772868) for a definition. – false Oct 16 '15 at 02:09

0 Answers0