prolog-toplevel

Prolog gives error “undefined procedure” when trying to use :-

六眼飞鱼酱① 提交于 2019-12-21 07:16:30
问题 I'm using SWI-Prolog on Windows and am getting the following error: 14 ?- parent(X, Y) :- child(Y, X). ERROR: toplevel: Undefined procedure: (:-)/2 (DWIM could not correct) I'm not entirely sure what's going on, as this worked last week and I am just starting to learn Prolog. 回答1: The FAQ says it all: http://www.swi-prolog.org/FAQ/ToplevelMode.html You need to create a file and write your program with rules there. The top level command line will only allow you to issue queries. 回答2: You can

Why does SWI-Prolog only give me the first answer?

我怕爱的太早我们不能终老 提交于 2019-12-19 05:59:24
问题 I'm new to Prolog. I'm just trying simple examples to learn. I have this .pl file with these lines: parent(pam,bob). parent(tom,bob). parent(tom,lio). parent(bob,ann). parent(bob,pat). parent(pat,jim). After consulting and testing, it only shows the first answer. For example: 5 ?- parent(X,Y). X = pam, Y = bob . Isn't it supposed to give all the combinations that satisfy the relation parent ? Do anyone have idea what the problem is? 回答1: don't hit enter after your first results shows, use

Prolog anonymous variable

こ雲淡風輕ζ 提交于 2019-12-18 05:43:51
问题 Here is what I have understood about Prolog variables. A single underscore stands for anonymous variable, which is like a new variable each time it occurs. A variable name starting with underscore like _W is not an anonymous variable. Or, the variable names generated inside Prolog, like _G189, is not considered anonymous: ?- append([1,2],X,Y). X = _G189 Y = [1, 2|_G189] Could you please help me understand? By the way, I got the above example from some tutorials, but when I run it in SWI

Prolog anonymous variable

送分小仙女□ 提交于 2019-12-18 05:43:27
问题 Here is what I have understood about Prolog variables. A single underscore stands for anonymous variable, which is like a new variable each time it occurs. A variable name starting with underscore like _W is not an anonymous variable. Or, the variable names generated inside Prolog, like _G189, is not considered anonymous: ?- append([1,2],X,Y). X = _G189 Y = [1, 2|_G189] Could you please help me understand? By the way, I got the above example from some tutorials, but when I run it in SWI

SWI-Prolog how to show entire answer (list)?

时光怂恿深爱的人放手 提交于 2019-12-17 16:47:26
问题 I'm trying to convert a string to a list of ascii-codes like so: 7 ?- string_to_list("I'm a big blue banana in space!", C). C = [73, 39, 109, 32, 97, 32, 98, 105, 103|...]. 8 ?- This doesn't give me the entire list as you can see, but I need it. This solution does not work: I can't press w since it gives me the answer and does a full stop. Neither does this: I can call the function alright, and it returns true, but the list still isn't fully displayed. 11 ?- set_prolog_flag(toplevel_print

SWI-Prolog - show long list

安稳与你 提交于 2019-12-17 06:49:47
问题 I'm using SWI-Prolog and I'm trying to print a list but if the list has more than 9 items - it look like that - [1, 15, 8, 22, 5, 19, 12, 25, 3|...] is there a way to show the whole list? 回答1: Have a look at: http://www.swi-prolog.org/FAQ/AllOutput.html The simple solution is to type w after the answer is given, i.e.: ?- n_queens_problem(10,X). X = [1, 3, 6, 8, 10, 5, 9, 2, 4|...] [write] X = [1, 3, 6, 8, 10, 5, 9, 2, 4, 7] After you have pressed the "w"-key "[write]" is displayed at the end

Prolog: stop condition?

南笙酒味 提交于 2019-12-13 08:49:31
问题 Here's a very trivial Prolog knowledge base: spouse(bill,cheryl). married(X,Y) :- spouse(X,Y). married(X,Y) :- spouse(Y,X). I ran the following queries. Note that sometimes the answer is the correct name (only), but other times the answer is the correct name and "false". 1 ?- married(bill,X). X = cheryl ; false. 2 ?- married(cheryl,X). X = bill. 3 ?- married(X,bill). X = cheryl. 4 ?- married(X,cheryl). X = bill ; false. Can someone explain this seemingly inconsistent behavior? Thanks in

Prolog showing results on the interpretator [duplicate]

二次信任 提交于 2019-12-13 04:25:19
问题 This question already has answers here : Using SWI-Prolog Interactively - Output Taken off (2 answers) Closed 5 years ago . I have this prolog predicate that computes the number of primes depending on the input count. However on the interpretator, it only shows the first 9 primes even though I input my required prime count as 10. the result looks like this as below L = [2, 3, 5, 7, 11, 13, 17, 19, 23|...] However, when I trace through using the graphical debugger, the correct results are

Prolog compiler return error

此生再无相见时 提交于 2019-12-12 20:46:40
问题 I have this hypothetical program to check if a path exists from point A to B. /*city rules*/ edge(phx, tuc). edge(tuc, ccg). edge(ccg, sf). connected(C1, C2) :- edge(C1, C2). connected(C1, C2) :- edge(C1, X), connected(X, C2). the problem is it returns true, then false. Where is the false coming from? 回答1: Let's look at the exact reply you got from Prolog! First you got a single true and on pressing SPACE or ; you eventually got: ?- connected(phx,sf). true ; false. So you got true ; false. as

Why does my replace/2 program always return false?

有些话、适合烂在心里 提交于 2019-12-11 17:33:47
问题 My goal is to replace the '_' with logic variables in a given list. My code: replace([], []). replace(['_'|As], [_|Bs]) :- replace(As, Bs). replace([A|As], [B|Bs]) :- A \= '_', B = '#', replace(As, Bs). It will return a proper list but always ends up with false . Any help please? 回答1: Any input that matches replace(['_'|As], [_|Bs]) , also matches replace([A|As], [B|Bs]) . This means that while the first clause is executed, a choice point is left for the latter one. After prolog has found the