Prolog If statement fact












0















I want to state a unique fact in my Prolog data base to change the outcome of my if statement.



My code is as follows:



suspect(Killer, mrBoddy) :-
affair(mrBoddy, Y),
married(X,Y),
write('Killer= '),
write(X), nl;
greedy(X),
write('Killer= '),
write(X), nl.


The output is



?- suspect(Killer, mrBoddy).                                      
Killer= profPlum

true ? ;
Killer= colMustard

yes


My Facts



affair(mrBoddy, msGreen).
affair(mrBoddy,missScarlet).
married(profPlum, msGreen).

rich(mrBoddy).
greedy(colMustard).
motive_to_kill_affair(profPlum).
motive_to_kill_greed(colMustard).


I want to add a fact that will change the output to only one "Killer". Doesn't matter who it is. How could I achieve this?










share|improve this question




















  • 1





    Could you please provide a Minimal, Complete, and Verifiable example?

    – Enigmativity
    Nov 26 '18 at 3:44











  • I believe I have edited it enough to provide the Minimal, Complete, and Verifiable example now.

    – BigO
    Nov 26 '18 at 3:49











  • Can you please explain what you mean by I want to add a fact that will change the ouput to only one "Killer"?

    – Enigmativity
    Nov 26 '18 at 3:56











  • Of course, right now when I run ?- suspect(Killer, mrBoddy). Killer = suspect_name_1 Killer = suspect_name_2 I want to add a fact that will change the output to ?-suspect(Killer,mrBoddy) Killer = unique_suspect.

    – BigO
    Nov 26 '18 at 3:58













  • I got that. I don't know what you mean by that.

    – Enigmativity
    Nov 26 '18 at 4:01
















0















I want to state a unique fact in my Prolog data base to change the outcome of my if statement.



My code is as follows:



suspect(Killer, mrBoddy) :-
affair(mrBoddy, Y),
married(X,Y),
write('Killer= '),
write(X), nl;
greedy(X),
write('Killer= '),
write(X), nl.


The output is



?- suspect(Killer, mrBoddy).                                      
Killer= profPlum

true ? ;
Killer= colMustard

yes


My Facts



affair(mrBoddy, msGreen).
affair(mrBoddy,missScarlet).
married(profPlum, msGreen).

rich(mrBoddy).
greedy(colMustard).
motive_to_kill_affair(profPlum).
motive_to_kill_greed(colMustard).


I want to add a fact that will change the output to only one "Killer". Doesn't matter who it is. How could I achieve this?










share|improve this question




















  • 1





    Could you please provide a Minimal, Complete, and Verifiable example?

    – Enigmativity
    Nov 26 '18 at 3:44











  • I believe I have edited it enough to provide the Minimal, Complete, and Verifiable example now.

    – BigO
    Nov 26 '18 at 3:49











  • Can you please explain what you mean by I want to add a fact that will change the ouput to only one "Killer"?

    – Enigmativity
    Nov 26 '18 at 3:56











  • Of course, right now when I run ?- suspect(Killer, mrBoddy). Killer = suspect_name_1 Killer = suspect_name_2 I want to add a fact that will change the output to ?-suspect(Killer,mrBoddy) Killer = unique_suspect.

    – BigO
    Nov 26 '18 at 3:58













  • I got that. I don't know what you mean by that.

    – Enigmativity
    Nov 26 '18 at 4:01














0












0








0








I want to state a unique fact in my Prolog data base to change the outcome of my if statement.



My code is as follows:



suspect(Killer, mrBoddy) :-
affair(mrBoddy, Y),
married(X,Y),
write('Killer= '),
write(X), nl;
greedy(X),
write('Killer= '),
write(X), nl.


The output is



?- suspect(Killer, mrBoddy).                                      
Killer= profPlum

true ? ;
Killer= colMustard

yes


My Facts



affair(mrBoddy, msGreen).
affair(mrBoddy,missScarlet).
married(profPlum, msGreen).

rich(mrBoddy).
greedy(colMustard).
motive_to_kill_affair(profPlum).
motive_to_kill_greed(colMustard).


I want to add a fact that will change the output to only one "Killer". Doesn't matter who it is. How could I achieve this?










share|improve this question
















I want to state a unique fact in my Prolog data base to change the outcome of my if statement.



My code is as follows:



suspect(Killer, mrBoddy) :-
affair(mrBoddy, Y),
married(X,Y),
write('Killer= '),
write(X), nl;
greedy(X),
write('Killer= '),
write(X), nl.


The output is



?- suspect(Killer, mrBoddy).                                      
Killer= profPlum

true ? ;
Killer= colMustard

yes


My Facts



affair(mrBoddy, msGreen).
affair(mrBoddy,missScarlet).
married(profPlum, msGreen).

rich(mrBoddy).
greedy(colMustard).
motive_to_kill_affair(profPlum).
motive_to_kill_greed(colMustard).


I want to add a fact that will change the output to only one "Killer". Doesn't matter who it is. How could I achieve this?







prolog






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 12:55









false

10.5k771144




10.5k771144










asked Nov 26 '18 at 3:34









BigOBigO

209




209








  • 1





    Could you please provide a Minimal, Complete, and Verifiable example?

    – Enigmativity
    Nov 26 '18 at 3:44











  • I believe I have edited it enough to provide the Minimal, Complete, and Verifiable example now.

    – BigO
    Nov 26 '18 at 3:49











  • Can you please explain what you mean by I want to add a fact that will change the ouput to only one "Killer"?

    – Enigmativity
    Nov 26 '18 at 3:56











  • Of course, right now when I run ?- suspect(Killer, mrBoddy). Killer = suspect_name_1 Killer = suspect_name_2 I want to add a fact that will change the output to ?-suspect(Killer,mrBoddy) Killer = unique_suspect.

    – BigO
    Nov 26 '18 at 3:58













  • I got that. I don't know what you mean by that.

    – Enigmativity
    Nov 26 '18 at 4:01














  • 1





    Could you please provide a Minimal, Complete, and Verifiable example?

    – Enigmativity
    Nov 26 '18 at 3:44











  • I believe I have edited it enough to provide the Minimal, Complete, and Verifiable example now.

    – BigO
    Nov 26 '18 at 3:49











  • Can you please explain what you mean by I want to add a fact that will change the ouput to only one "Killer"?

    – Enigmativity
    Nov 26 '18 at 3:56











  • Of course, right now when I run ?- suspect(Killer, mrBoddy). Killer = suspect_name_1 Killer = suspect_name_2 I want to add a fact that will change the output to ?-suspect(Killer,mrBoddy) Killer = unique_suspect.

    – BigO
    Nov 26 '18 at 3:58













  • I got that. I don't know what you mean by that.

    – Enigmativity
    Nov 26 '18 at 4:01








1




1





Could you please provide a Minimal, Complete, and Verifiable example?

– Enigmativity
Nov 26 '18 at 3:44





Could you please provide a Minimal, Complete, and Verifiable example?

– Enigmativity
Nov 26 '18 at 3:44













I believe I have edited it enough to provide the Minimal, Complete, and Verifiable example now.

– BigO
Nov 26 '18 at 3:49





I believe I have edited it enough to provide the Minimal, Complete, and Verifiable example now.

– BigO
Nov 26 '18 at 3:49













Can you please explain what you mean by I want to add a fact that will change the ouput to only one "Killer"?

– Enigmativity
Nov 26 '18 at 3:56





Can you please explain what you mean by I want to add a fact that will change the ouput to only one "Killer"?

– Enigmativity
Nov 26 '18 at 3:56













Of course, right now when I run ?- suspect(Killer, mrBoddy). Killer = suspect_name_1 Killer = suspect_name_2 I want to add a fact that will change the output to ?-suspect(Killer,mrBoddy) Killer = unique_suspect.

– BigO
Nov 26 '18 at 3:58







Of course, right now when I run ?- suspect(Killer, mrBoddy). Killer = suspect_name_1 Killer = suspect_name_2 I want to add a fact that will change the output to ?-suspect(Killer,mrBoddy) Killer = unique_suspect.

– BigO
Nov 26 '18 at 3:58















I got that. I don't know what you mean by that.

– Enigmativity
Nov 26 '18 at 4:01





I got that. I don't know what you mean by that.

– Enigmativity
Nov 26 '18 at 4:01












1 Answer
1






active

oldest

votes


















0














Based on your query



suspect(Killer, mrBoddy) :-
affair(mrBoddy, Y),
married(X,Y),
write('Killer= '),
write(X), nl;
greedy(X),
write('Killer= '),
write(X), nl.


which is an OR query (;/2) there are really two queries in one.



Since the variable Killer is one of the parameters of the query there is no need to add the write statements



    write('Killer= '),
write(X),
nl


In the predicate you have hard-coded the second parameter, mrBoddy,



suspect(Killer, mrBoddy)


Prolog starts variables with upper case letters and values with lower case letters.



The first query is



suspect_1(Killer, mrBoddy) :-
affair(mrBoddy, X),
married(Killer,X).


for which the result is



?- suspect_1(Killer,mrBoddy).
Killer = profPlum ;
false.


The second query is



suspect_2(Killer, mrBoddy) :-
greedy(Killer).


for which the result is



?- suspect_2(Killer,mrBoddy).
Killer = colMustard.



I want to add a fact that will change the output to only one "Killer".




Since you are only allowing the facts to be changed and the query is an OR query that is working, no matter how many facts you add, you will always get at least two answers.



You can change the query or remove a fact.



If you want to ask additional questions then please post new questions.






share|improve this answer

























    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%2f53474479%2fprolog-if-statement-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









    0














    Based on your query



    suspect(Killer, mrBoddy) :-
    affair(mrBoddy, Y),
    married(X,Y),
    write('Killer= '),
    write(X), nl;
    greedy(X),
    write('Killer= '),
    write(X), nl.


    which is an OR query (;/2) there are really two queries in one.



    Since the variable Killer is one of the parameters of the query there is no need to add the write statements



        write('Killer= '),
    write(X),
    nl


    In the predicate you have hard-coded the second parameter, mrBoddy,



    suspect(Killer, mrBoddy)


    Prolog starts variables with upper case letters and values with lower case letters.



    The first query is



    suspect_1(Killer, mrBoddy) :-
    affair(mrBoddy, X),
    married(Killer,X).


    for which the result is



    ?- suspect_1(Killer,mrBoddy).
    Killer = profPlum ;
    false.


    The second query is



    suspect_2(Killer, mrBoddy) :-
    greedy(Killer).


    for which the result is



    ?- suspect_2(Killer,mrBoddy).
    Killer = colMustard.



    I want to add a fact that will change the output to only one "Killer".




    Since you are only allowing the facts to be changed and the query is an OR query that is working, no matter how many facts you add, you will always get at least two answers.



    You can change the query or remove a fact.



    If you want to ask additional questions then please post new questions.






    share|improve this answer






























      0














      Based on your query



      suspect(Killer, mrBoddy) :-
      affair(mrBoddy, Y),
      married(X,Y),
      write('Killer= '),
      write(X), nl;
      greedy(X),
      write('Killer= '),
      write(X), nl.


      which is an OR query (;/2) there are really two queries in one.



      Since the variable Killer is one of the parameters of the query there is no need to add the write statements



          write('Killer= '),
      write(X),
      nl


      In the predicate you have hard-coded the second parameter, mrBoddy,



      suspect(Killer, mrBoddy)


      Prolog starts variables with upper case letters and values with lower case letters.



      The first query is



      suspect_1(Killer, mrBoddy) :-
      affair(mrBoddy, X),
      married(Killer,X).


      for which the result is



      ?- suspect_1(Killer,mrBoddy).
      Killer = profPlum ;
      false.


      The second query is



      suspect_2(Killer, mrBoddy) :-
      greedy(Killer).


      for which the result is



      ?- suspect_2(Killer,mrBoddy).
      Killer = colMustard.



      I want to add a fact that will change the output to only one "Killer".




      Since you are only allowing the facts to be changed and the query is an OR query that is working, no matter how many facts you add, you will always get at least two answers.



      You can change the query or remove a fact.



      If you want to ask additional questions then please post new questions.






      share|improve this answer




























        0












        0








        0







        Based on your query



        suspect(Killer, mrBoddy) :-
        affair(mrBoddy, Y),
        married(X,Y),
        write('Killer= '),
        write(X), nl;
        greedy(X),
        write('Killer= '),
        write(X), nl.


        which is an OR query (;/2) there are really two queries in one.



        Since the variable Killer is one of the parameters of the query there is no need to add the write statements



            write('Killer= '),
        write(X),
        nl


        In the predicate you have hard-coded the second parameter, mrBoddy,



        suspect(Killer, mrBoddy)


        Prolog starts variables with upper case letters and values with lower case letters.



        The first query is



        suspect_1(Killer, mrBoddy) :-
        affair(mrBoddy, X),
        married(Killer,X).


        for which the result is



        ?- suspect_1(Killer,mrBoddy).
        Killer = profPlum ;
        false.


        The second query is



        suspect_2(Killer, mrBoddy) :-
        greedy(Killer).


        for which the result is



        ?- suspect_2(Killer,mrBoddy).
        Killer = colMustard.



        I want to add a fact that will change the output to only one "Killer".




        Since you are only allowing the facts to be changed and the query is an OR query that is working, no matter how many facts you add, you will always get at least two answers.



        You can change the query or remove a fact.



        If you want to ask additional questions then please post new questions.






        share|improve this answer















        Based on your query



        suspect(Killer, mrBoddy) :-
        affair(mrBoddy, Y),
        married(X,Y),
        write('Killer= '),
        write(X), nl;
        greedy(X),
        write('Killer= '),
        write(X), nl.


        which is an OR query (;/2) there are really two queries in one.



        Since the variable Killer is one of the parameters of the query there is no need to add the write statements



            write('Killer= '),
        write(X),
        nl


        In the predicate you have hard-coded the second parameter, mrBoddy,



        suspect(Killer, mrBoddy)


        Prolog starts variables with upper case letters and values with lower case letters.



        The first query is



        suspect_1(Killer, mrBoddy) :-
        affair(mrBoddy, X),
        married(Killer,X).


        for which the result is



        ?- suspect_1(Killer,mrBoddy).
        Killer = profPlum ;
        false.


        The second query is



        suspect_2(Killer, mrBoddy) :-
        greedy(Killer).


        for which the result is



        ?- suspect_2(Killer,mrBoddy).
        Killer = colMustard.



        I want to add a fact that will change the output to only one "Killer".




        Since you are only allowing the facts to be changed and the query is an OR query that is working, no matter how many facts you add, you will always get at least two answers.



        You can change the query or remove a fact.



        If you want to ask additional questions then please post new questions.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 13:01

























        answered Nov 26 '18 at 11:41









        Guy CoderGuy Coder

        15.4k43983




        15.4k43983






























            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%2f53474479%2fprolog-if-statement-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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)