swi-prolog

How to use predicate transpose in SWI-Prolog?

那年仲夏 提交于 2019-12-13 05:15:56
问题 Hi guys I want to use predicate transpose(Matrix0, Matrix) in SWI-Prolog which holds when Matrix0 and Matrix are lists of lists, and the “columns” of each are the “rows” of the other. The problem is when I added :- ensure_loaded(library(clpfd)). into my source file and tried to use it, I got this % library(occurs) compiled into occurs 0.00 sec, 14 clauses % library(apply_macros) compiled into apply_macros 0.00 sec, 44 clauses % library(assoc) compiled into assoc 0.00 sec, 103 clauses ERROR:

How does `random_variable `random_value` work in SWI-Prolog's labeling/2?

南楼画角 提交于 2019-12-13 03:01:34
问题 I've seen it's possible to label cplfd variables using a random method by adding the following options to labeling/2 : labeling([random_variable(N),random_value(M)],List). Where M and N are supposed to be integers, I think. However I am not able to find any information about those options in SWI-Prolog's documentation page. How can they be used? 回答1: In the CLP(FD) library there's this: selection(random_variable(Seed)) :- must_be(integer, Seed), set_random(seed(Seed)). % TODO: random_variable

swi-prolog: remove '|:' before user input in compiled program

吃可爱长大的小学妹 提交于 2019-12-12 22:17:39
问题 Whenever I compile anything with swi-prolog, it adds |: before user input to show that you are supposed to write something, which would be fine, but I need to pipe the output of this program to another program, preferably without the |: . My compilation options are: swipl -nodebug -g true -O -q --toplevel=quiet --stand_alone=true -o main -c main.pl 回答1: You need to say prompt(_, '') somewhere in your program before you start reading and writing to standard streams. From the entry for prompt/2

Creating a SPARQL parameterized query using append/3 predicate

旧城冷巷雨未停 提交于 2019-12-12 20:37:22
问题 Related to my previous post: How to parameterize a SPARQL query in SWI Prolog? In order to exercise, I was trying to implement a predicate that builds and executes a SPARQL query using only the append/3 predicate (differently from the solution proposed in my old post) but it doesn't work well. This is my predicate: buildQuery(Place, Query, Row) :- % Q1 = 'select COUNT(*) where {?place a dbpedia-owl:Place ; rdfs:label " Q1 = [39, 115, 101, 108, 101, 99, 116, 32, 67, 79, 85, 78, 84, 40, 42, 41,

SWI-Prolog: How to get unicode char from escaped string?

。_饼干妹妹 提交于 2019-12-12 20:09:01
问题 I have a problem, I've got an escaped string for example "\\u0026" and I need this to transform to unicode char '\u0026'. Tricks like string_concat('\\', S, "\\u0026"), write(S). didn't help, because it will remove \ not only the escape . So basically my problem is, how to remove escape chars from the string. EDIT: Oh, I've just noticed, that stackoverflow also plays with escape \. write_canonical/1 gives me "\\u0026", how to transform that into a single '&' char? 回答1: In ISO Prolog a char is

JPL/SWI Prolog not working

筅森魡賤 提交于 2019-12-12 19:17:25
问题 I'm trying to use the SWI-Prolog JPL library, but I'm having problems. I'm trying to let my Eclipse project access JPL, but when I try to start the program, I get the following error: Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no jpl in java.library.path I copied the jpl.jar into my project directory, and I set it on the build path. Additionally, I pass the following VM arguments: -Djava.library.path="C:\Program Files\Prolog\bin" (That's the directory where Prolog

Error while using command prompt or shell using process_create/3 in SWI Prolog

只谈情不闲聊 提交于 2019-12-12 19:05:53
问题 On Windows 7, when I used process_create/3 in SWI Prolog to open an application like Notepad.exe, the notepad opens. However, it doesn't work for applications that use command prompt. As an example, when I tried to open the command prompt window, using: main :- process_create('C:\\WINDOWS\\system32\\cmd.exe',[] ,[]). which gives an ERROR: Process "c:\windows\system32\cmd.exe": exit status: 1 Similarly, when trying it to open powershell.exe, it doesn't work either. the console just hangs,

SWI-Prolog threads with stream output

落爺英雄遲暮 提交于 2019-12-12 15:58:37
问题 If I have a program like the one below, does prolog try to prove maximum/3 all three times in parallel? i.e does each thread get its own core (assuming available on the computer)? My actual program takes about 2 hours to run a predicate in the position of maximum/3 here and I have 70 equivalent of pair/2 that will need to be calculated. Would this approach work? If not why not? I have set the program running but it seems from the output that it is just doing one thread at a time. maximum(X,Y

Reversible predicates and Strings in SWI-Prolog

社会主义新天地 提交于 2019-12-12 12:14:26
问题 append/3 is a very powerful predicate. Suppose I want a predicate that works the same way but for SWI-Prolog's strings. The easiest approach I see is to transform those strings into lists with string_codes/2 , then apply append/3 , then use string_codes/2 back. The big problem with this approach is that string_codes/2 does not work if both variables are not unified. Here is an extremely ugly solution I came up with, which checks which strings are unified to apply string_codes/2 when needed:

Prolog Count The Unique Identifiers In Fact [closed]

陌路散爱 提交于 2019-12-12 02:45:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . We have facts studies(cse, plc). studies(cse, da). studies(it, se). studies(it, plc). where studies(x,y) means that branch x studies module y . Now I Want to define Rule To count number of modules in all. like here it will be 3.that are (plc,da,se).PLZ HELP. What will be the query to find how many subjects