0

I wanted to know how I could use tranpose and findall to list all the variables in a predictate and display it as matrix?

so this is the predicate with all the variables.

across(2,4,2,4).
across(2,10,2,4).   
across(3,4,4,12).
across(3,10,2,6).
across(4,3,2,6).
across(4,6,4,10).
  • This is a little unclear. Why do you need transpose? Please provide an example output given the data you are showing. – lurker Apr 04 '16 at 20:21
  • @lurker sorry I got a little ahead of myself, I think the main thing I want to figure out is how to use findall to call the predicate above. – user6105558 Apr 04 '16 at 21:05
  • Did you look at the documentation and try anything? :) For example, if you want to collect all the arguments in a matrix: `findall([A,B,C,D], across(A,B,C,D), Results).` The first argument is the pattern for what you're collecting, second argument is the rule to apply, third argument is the list of results. – lurker Apr 04 '16 at 21:08
  • @lurker yes I did but it was all specified like the following findall(Object,Goal,List). so i was not sure how to use it. Also I was not sure on how to call it from a separate file instead of typing it into prolog – user6105558 Apr 04 '16 at 21:12
  • If you go to the [SWI documentation for `findall/3`](http://www.swi-prolog.org/pldoc/doc_for?object=findall/3) it says that *it's the equivalent of [`bagof/3`](http://www.swi-prolog.org/pldoc/man?predicate=bagof/3)...* and clicking [`bagof/3`](http://www.swi-prolog.org/pldoc/man?predicate=bagof/3) will show a couple of examples. – lurker Apr 04 '16 at 21:16

1 Answers1

0

Probably easier to store it in a predicate.

getAcross(List) :- findall([A,B,C,D], across(A,B,C,D), List).

So getAcross(X) will store a list of [[A,B,C,D],[A,B,C,D]... etc

If you're talking about transposing a matrix for example, you may only need to that if you have down constraints as well. :)

lurker
  • 56,987
  • 9
  • 69
  • 103
eponini
  • 74
  • 1
  • 13