Prolog If statement fact
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
|
show 1 more comment
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
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 byI 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
|
show 1 more comment
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
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
prolog
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 byI 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
|
show 1 more comment
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 byI 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
|
show 1 more comment
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 26 '18 at 13:01
answered Nov 26 '18 at 11:41
Guy CoderGuy Coder
15.4k43983
15.4k43983
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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