Prolog: Give list to a fact



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















Lets say I'm looking for someones friends.



friend(mary, peter).
friend(mary, paul).
friend(mary, john).
friend(mary, justin).

friend(chris, peter).
friend(chris, paul).
friend(chris, conner).
friend(chris, louis).

friend(tyler, justin).
friend(tyler, lindsey).
friend(tyler, frank).
friend(tyler, paul).

friend(dan, justin).
friend(dan, conner).
friend(dan, frank).
friend(dan, peter).


In the above example I know that I can do something like



friend(X, paul).


which will tell me everyone paul is friends with



or also



findall(X, friend(X, paul), L).


which will return a list of everyone paul is friends with.



Let's say that I want to go a little bit deeper in my search and refine it. So let's say that I was to do



findall(X, friend(X, paul), A).


To get A to be a list of [mary, chris, tyler]. But then I wanted to further refine that search. I want to be able to put the list into the function (I know this isnt valid but this is my thought pattern for what I want to do) for something like



findall(A, friend(A, peter), B).


To get back just [mary, chris] this time. And then even FURTHER refine it to say



findall(B, friend(B, conner), C).


To finally conclude my search to find [chris]



Is this possible? Is there a better or even possible way to do this?










share|improve this question






























    1















    Lets say I'm looking for someones friends.



    friend(mary, peter).
    friend(mary, paul).
    friend(mary, john).
    friend(mary, justin).

    friend(chris, peter).
    friend(chris, paul).
    friend(chris, conner).
    friend(chris, louis).

    friend(tyler, justin).
    friend(tyler, lindsey).
    friend(tyler, frank).
    friend(tyler, paul).

    friend(dan, justin).
    friend(dan, conner).
    friend(dan, frank).
    friend(dan, peter).


    In the above example I know that I can do something like



    friend(X, paul).


    which will tell me everyone paul is friends with



    or also



    findall(X, friend(X, paul), L).


    which will return a list of everyone paul is friends with.



    Let's say that I want to go a little bit deeper in my search and refine it. So let's say that I was to do



    findall(X, friend(X, paul), A).


    To get A to be a list of [mary, chris, tyler]. But then I wanted to further refine that search. I want to be able to put the list into the function (I know this isnt valid but this is my thought pattern for what I want to do) for something like



    findall(A, friend(A, peter), B).


    To get back just [mary, chris] this time. And then even FURTHER refine it to say



    findall(B, friend(B, conner), C).


    To finally conclude my search to find [chris]



    Is this possible? Is there a better or even possible way to do this?










    share|improve this question


























      1












      1








      1








      Lets say I'm looking for someones friends.



      friend(mary, peter).
      friend(mary, paul).
      friend(mary, john).
      friend(mary, justin).

      friend(chris, peter).
      friend(chris, paul).
      friend(chris, conner).
      friend(chris, louis).

      friend(tyler, justin).
      friend(tyler, lindsey).
      friend(tyler, frank).
      friend(tyler, paul).

      friend(dan, justin).
      friend(dan, conner).
      friend(dan, frank).
      friend(dan, peter).


      In the above example I know that I can do something like



      friend(X, paul).


      which will tell me everyone paul is friends with



      or also



      findall(X, friend(X, paul), L).


      which will return a list of everyone paul is friends with.



      Let's say that I want to go a little bit deeper in my search and refine it. So let's say that I was to do



      findall(X, friend(X, paul), A).


      To get A to be a list of [mary, chris, tyler]. But then I wanted to further refine that search. I want to be able to put the list into the function (I know this isnt valid but this is my thought pattern for what I want to do) for something like



      findall(A, friend(A, peter), B).


      To get back just [mary, chris] this time. And then even FURTHER refine it to say



      findall(B, friend(B, conner), C).


      To finally conclude my search to find [chris]



      Is this possible? Is there a better or even possible way to do this?










      share|improve this question
















      Lets say I'm looking for someones friends.



      friend(mary, peter).
      friend(mary, paul).
      friend(mary, john).
      friend(mary, justin).

      friend(chris, peter).
      friend(chris, paul).
      friend(chris, conner).
      friend(chris, louis).

      friend(tyler, justin).
      friend(tyler, lindsey).
      friend(tyler, frank).
      friend(tyler, paul).

      friend(dan, justin).
      friend(dan, conner).
      friend(dan, frank).
      friend(dan, peter).


      In the above example I know that I can do something like



      friend(X, paul).


      which will tell me everyone paul is friends with



      or also



      findall(X, friend(X, paul), L).


      which will return a list of everyone paul is friends with.



      Let's say that I want to go a little bit deeper in my search and refine it. So let's say that I was to do



      findall(X, friend(X, paul), A).


      To get A to be a list of [mary, chris, tyler]. But then I wanted to further refine that search. I want to be able to put the list into the function (I know this isnt valid but this is my thought pattern for what I want to do) for something like



      findall(A, friend(A, peter), B).


      To get back just [mary, chris] this time. And then even FURTHER refine it to say



      findall(B, friend(B, conner), C).


      To finally conclude my search to find [chris]



      Is this possible? Is there a better or even possible way to do this?







      prolog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 20:25









      false

      10.5k773151




      10.5k773151










      asked Nov 13 '18 at 22:29









      JustinJustin

      82




      82






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Chain conditions



          Given I understood it correctly, you want to generate a list of people that are friends with paul, peter and connor. We can do that by "constructing" a goal that aims to satisfy the three conditions:



          findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).


          or another conjunction of conditions. These then give:



          ?- findall(F, (friend(F, paul)), L).
          L = [mary, chris, tyler].

          ?- findall(F, (friend(F, paul), friend(F, peter)), L).
          L = [mary, chris].

          ?- findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).
          L = [chris].


          Filter an existing list with member/2 in the goal



          Or we can also use two calls, and use member/2 to "emulate" an intersection like:



          findall(F, friend(F, paul), L1),
          findall(F, (member(F, L1), friend(F, peter)), L2).


          here we thus use member/2 such that F2 only takes values from L1 (the result of the initial findall/3), but I think the first way is cleaner and more self explaining: we want after all a list of Fs that are friends with paul, and peter, and conner.



          Using maplist/2 to obtain people that are friends with everybody in a list



          We can also find the people that are friends with a list of people by using maplist/2 here:



          findall(F, maplist(friend(F), [paul, peter, conner]), L).


          Post-process with an intersection



          We can also make two separate findall/3 calls, and then calculate the intersection:



          findall(F, friend(F, paul), L1),
          findall(F, friend(F, paul), L2),
          intersection(L1, L2, M).


          Here M will thus contain the elements that are both in L1 and L2. But a potential problem here is that the second predicate can generate a lot of results that were not possible with given we filtered with the values of the first predicate.






          share|improve this answer

























          • we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

            – Justin
            Nov 13 '18 at 22:41












          • @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

            – Willem Van Onsem
            Nov 13 '18 at 22:42











          • @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

            – Willem Van Onsem
            Nov 13 '18 at 22:45











          • The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

            – Justin
            Nov 13 '18 at 22:46












          • @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

            – Willem Van Onsem
            Nov 13 '18 at 22:51











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290479%2fprolog-give-list-to-a-fact%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Chain conditions



          Given I understood it correctly, you want to generate a list of people that are friends with paul, peter and connor. We can do that by "constructing" a goal that aims to satisfy the three conditions:



          findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).


          or another conjunction of conditions. These then give:



          ?- findall(F, (friend(F, paul)), L).
          L = [mary, chris, tyler].

          ?- findall(F, (friend(F, paul), friend(F, peter)), L).
          L = [mary, chris].

          ?- findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).
          L = [chris].


          Filter an existing list with member/2 in the goal



          Or we can also use two calls, and use member/2 to "emulate" an intersection like:



          findall(F, friend(F, paul), L1),
          findall(F, (member(F, L1), friend(F, peter)), L2).


          here we thus use member/2 such that F2 only takes values from L1 (the result of the initial findall/3), but I think the first way is cleaner and more self explaining: we want after all a list of Fs that are friends with paul, and peter, and conner.



          Using maplist/2 to obtain people that are friends with everybody in a list



          We can also find the people that are friends with a list of people by using maplist/2 here:



          findall(F, maplist(friend(F), [paul, peter, conner]), L).


          Post-process with an intersection



          We can also make two separate findall/3 calls, and then calculate the intersection:



          findall(F, friend(F, paul), L1),
          findall(F, friend(F, paul), L2),
          intersection(L1, L2, M).


          Here M will thus contain the elements that are both in L1 and L2. But a potential problem here is that the second predicate can generate a lot of results that were not possible with given we filtered with the values of the first predicate.






          share|improve this answer

























          • we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

            – Justin
            Nov 13 '18 at 22:41












          • @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

            – Willem Van Onsem
            Nov 13 '18 at 22:42











          • @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

            – Willem Van Onsem
            Nov 13 '18 at 22:45











          • The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

            – Justin
            Nov 13 '18 at 22:46












          • @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

            – Willem Van Onsem
            Nov 13 '18 at 22:51















          1














          Chain conditions



          Given I understood it correctly, you want to generate a list of people that are friends with paul, peter and connor. We can do that by "constructing" a goal that aims to satisfy the three conditions:



          findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).


          or another conjunction of conditions. These then give:



          ?- findall(F, (friend(F, paul)), L).
          L = [mary, chris, tyler].

          ?- findall(F, (friend(F, paul), friend(F, peter)), L).
          L = [mary, chris].

          ?- findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).
          L = [chris].


          Filter an existing list with member/2 in the goal



          Or we can also use two calls, and use member/2 to "emulate" an intersection like:



          findall(F, friend(F, paul), L1),
          findall(F, (member(F, L1), friend(F, peter)), L2).


          here we thus use member/2 such that F2 only takes values from L1 (the result of the initial findall/3), but I think the first way is cleaner and more self explaining: we want after all a list of Fs that are friends with paul, and peter, and conner.



          Using maplist/2 to obtain people that are friends with everybody in a list



          We can also find the people that are friends with a list of people by using maplist/2 here:



          findall(F, maplist(friend(F), [paul, peter, conner]), L).


          Post-process with an intersection



          We can also make two separate findall/3 calls, and then calculate the intersection:



          findall(F, friend(F, paul), L1),
          findall(F, friend(F, paul), L2),
          intersection(L1, L2, M).


          Here M will thus contain the elements that are both in L1 and L2. But a potential problem here is that the second predicate can generate a lot of results that were not possible with given we filtered with the values of the first predicate.






          share|improve this answer

























          • we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

            – Justin
            Nov 13 '18 at 22:41












          • @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

            – Willem Van Onsem
            Nov 13 '18 at 22:42











          • @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

            – Willem Van Onsem
            Nov 13 '18 at 22:45











          • The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

            – Justin
            Nov 13 '18 at 22:46












          • @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

            – Willem Van Onsem
            Nov 13 '18 at 22:51













          1












          1








          1







          Chain conditions



          Given I understood it correctly, you want to generate a list of people that are friends with paul, peter and connor. We can do that by "constructing" a goal that aims to satisfy the three conditions:



          findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).


          or another conjunction of conditions. These then give:



          ?- findall(F, (friend(F, paul)), L).
          L = [mary, chris, tyler].

          ?- findall(F, (friend(F, paul), friend(F, peter)), L).
          L = [mary, chris].

          ?- findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).
          L = [chris].


          Filter an existing list with member/2 in the goal



          Or we can also use two calls, and use member/2 to "emulate" an intersection like:



          findall(F, friend(F, paul), L1),
          findall(F, (member(F, L1), friend(F, peter)), L2).


          here we thus use member/2 such that F2 only takes values from L1 (the result of the initial findall/3), but I think the first way is cleaner and more self explaining: we want after all a list of Fs that are friends with paul, and peter, and conner.



          Using maplist/2 to obtain people that are friends with everybody in a list



          We can also find the people that are friends with a list of people by using maplist/2 here:



          findall(F, maplist(friend(F), [paul, peter, conner]), L).


          Post-process with an intersection



          We can also make two separate findall/3 calls, and then calculate the intersection:



          findall(F, friend(F, paul), L1),
          findall(F, friend(F, paul), L2),
          intersection(L1, L2, M).


          Here M will thus contain the elements that are both in L1 and L2. But a potential problem here is that the second predicate can generate a lot of results that were not possible with given we filtered with the values of the first predicate.






          share|improve this answer















          Chain conditions



          Given I understood it correctly, you want to generate a list of people that are friends with paul, peter and connor. We can do that by "constructing" a goal that aims to satisfy the three conditions:



          findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).


          or another conjunction of conditions. These then give:



          ?- findall(F, (friend(F, paul)), L).
          L = [mary, chris, tyler].

          ?- findall(F, (friend(F, paul), friend(F, peter)), L).
          L = [mary, chris].

          ?- findall(F, (friend(F, paul), friend(F, peter), friend(F, conner)), L).
          L = [chris].


          Filter an existing list with member/2 in the goal



          Or we can also use two calls, and use member/2 to "emulate" an intersection like:



          findall(F, friend(F, paul), L1),
          findall(F, (member(F, L1), friend(F, peter)), L2).


          here we thus use member/2 such that F2 only takes values from L1 (the result of the initial findall/3), but I think the first way is cleaner and more self explaining: we want after all a list of Fs that are friends with paul, and peter, and conner.



          Using maplist/2 to obtain people that are friends with everybody in a list



          We can also find the people that are friends with a list of people by using maplist/2 here:



          findall(F, maplist(friend(F), [paul, peter, conner]), L).


          Post-process with an intersection



          We can also make two separate findall/3 calls, and then calculate the intersection:



          findall(F, friend(F, paul), L1),
          findall(F, friend(F, paul), L2),
          intersection(L1, L2, M).


          Here M will thus contain the elements that are both in L1 and L2. But a potential problem here is that the second predicate can generate a lot of results that were not possible with given we filtered with the values of the first predicate.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 22:51

























          answered Nov 13 '18 at 22:35









          Willem Van OnsemWillem Van Onsem

          151k16151238




          151k16151238












          • we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

            – Justin
            Nov 13 '18 at 22:41












          • @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

            – Willem Van Onsem
            Nov 13 '18 at 22:42











          • @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

            – Willem Van Onsem
            Nov 13 '18 at 22:45











          • The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

            – Justin
            Nov 13 '18 at 22:46












          • @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

            – Willem Van Onsem
            Nov 13 '18 at 22:51

















          • we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

            – Justin
            Nov 13 '18 at 22:41












          • @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

            – Willem Van Onsem
            Nov 13 '18 at 22:42











          • @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

            – Willem Van Onsem
            Nov 13 '18 at 22:45











          • The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

            – Justin
            Nov 13 '18 at 22:46












          • @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

            – Willem Van Onsem
            Nov 13 '18 at 22:51
















          we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

          – Justin
          Nov 13 '18 at 22:41






          we're kind of on the right track. except I want a user to be able to say "refine the search by adding another friend" to narrow down the final person or person's I'm looking for. So I'm trying to recursively call a function that keeps adding a friend to the list. Like the first time they would say paul. Then get a list back and refine that search by saying peter. Then the third time around refine it by calling conner or if they'd like just stop at the first 2 names and be happy with the list of [mary, chris]. My solution was to keep pushing L to say only search from this specific list.

          – Justin
          Nov 13 '18 at 22:41














          @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

          – Willem Van Onsem
          Nov 13 '18 at 22:42





          @Justin: well that is the second strategy: here we thus use member/2 over the first list (L1) to filter that one further. But note that you do not need to call the findall/3s immediately after another, the second findall is a "refiner".

          – Willem Van Onsem
          Nov 13 '18 at 22:42













          @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

          – Willem Van Onsem
          Nov 13 '18 at 22:45





          @Justin: furthermore if you want to process a list of persons, then the third approach is likely the most elegant.

          – Willem Van Onsem
          Nov 13 '18 at 22:45













          The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

          – Justin
          Nov 13 '18 at 22:46






          The limit to that is you have to redefine the query every time you want to add a new name to search for. If I could just push the list L to the fact in some way to say findall(L, (friend(L, paul), M). where L is the list generated the first go around and M is the new list, I could recursively call this over and over with one line of code. Does that make sense what I'm trying to accomplish? Then all I have to change is paul, which could really just be from a variable X.

          – Justin
          Nov 13 '18 at 22:46














          @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

          – Willem Van Onsem
          Nov 13 '18 at 22:51





          @Justin: but here you do that with one line of code, you write findall(F, (member(F, L), friend(F, peter)), M). You only extend the "goal" a bit with member/2`, but that does not really "restricts" the freedom to alter all kinds of goals.

          – Willem Van Onsem
          Nov 13 '18 at 22:51



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290479%2fprolog-give-list-to-a-fact%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

          Crossroads (UK TV series)

          ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế