swi-prolog

After the first answer, Prolog shows the error “char_code/2: Cannot represent due to 'character_code'”

﹥>﹥吖頭↗ 提交于 2019-11-29 16:21:40
In normal situation, we can use ";" to show the next answer if there is one. But if I do this, it shows me error: char_code/2: Cannot represent due to 'character_code' In stead of ";" , I use "shift + ;" , and prolog gives me a prompt Unknown action: : (h for help) Action? then if I input ";" , the designable answers will be shown one by one. What is the problem? Use swipl-win.exe instead of swipl.exe can solve this problem.(I tried 6.x and 7.x) By the way, swipl works well under MacOS. 来源: https://stackoverflow.com/questions/23133168/after-the-first-answer-prolog-shows-the-error-char-code-2

How to use list constructors (./2) in SWI-Prolog

这一生的挚爱 提交于 2019-11-29 14:40:29
I am trying to use list constructor in SWI-Prolog, but am getting 'dict' expected error. For example, .(a, []) == [a]. ERROR: Type error: `dict' expected, found `a' (an atom) ERROR: In: ERROR: [11] throw(error(type_error(dict,a),_14808)) ERROR: [10] '$type_error'(dict,a) at /Applications/SWI-Prolog.app/Contents/swipl/boot/init.pl:3369 ERROR: [9] '$dicts':'.'(a,[],_14874) at /Applications/SWI-Prolog.app/Contents/swipl/boot/dicts.pl:46 ERROR: [8] '<meta-call>'(user:(...,...)) <foreign> ERROR: [7] <user> Exception: (9) '.'(a, [], _14200) ? Could anyone help me configure this functionality? SWI

JPL/SWI Prolog configuration failure

≯℡__Kan透↙ 提交于 2019-11-29 12:51:50
I'm configuring the JPL right now, and wanna work with swi-prolog using java. I downloaded the newest stable version of SWI-Prolog, which is 6.2.0, and installed in D:\swipl First, I added the following path to the PATH virable: D:\swipl\bin, which should include all dll files needed. Then, I added the following path to the CLASSPATH virable: D:swipl\lib\jpl.jar, which should be the jar file needed. When I tried to run the versions example provided, I got the following error: Exception in thread "main" java.lang.UnsatisfiedLinkError: jpl.fli.Prolog.thread_self()I at jpl.fli.Prolog.thread_self

How to use SWI-Prolog ./2 function?

坚强是说给别人听的谎言 提交于 2019-11-28 14:10:57
Need example using SWI-Prolog ./2 . The signature is .(+Int,[]) Also if there is a name for this operator it would be nice to know. Searching for '.' is senseless. The closest to a name is from SWI documentation section F.3 Arithmetic Functions List of one character: character code What I tried ?- X is .(97,[]). results in ERROR: Type error: `dict' expected, found `97' (an integer) ERROR: In: ERROR: [11] throw(error(type_error(dict,97),_5812)) ERROR: [8] '<meta-call>'(user:(...,...)) <foreign> ERROR: [7] <user> ERROR: ERROR: Note: some frames are missing due to last-call optimization. ERROR:

After the first answer, Prolog shows the error “char_code/2: Cannot represent due to 'character_code'”

放肆的年华 提交于 2019-11-28 10:05:46
问题 In normal situation, we can use ";" to show the next answer if there is one. But if I do this, it shows me error: char_code/2: Cannot represent due to 'character_code' In stead of ";" , I use "shift + ;" , and prolog gives me a prompt Unknown action: : (h for help) Action? then if I input ";" , the designable answers will be shown one by one. What is the problem? 回答1: Use swipl-win.exe instead of swipl.exe can solve this problem.(I tried 6.x and 7.x) By the way, swipl works well under MacOS.

What are the optimal green cuts for successor arithmetics sum?

旧巷老猫 提交于 2019-11-28 07:42:31
问题 To grok green cuts in Prolog I am trying to add them to the standard definition of sum in successor arithmetics (see predicate plus in What's the SLD tree for this query?). The idea is to "clean up" the output as much as possible by eliminating all useless backtracks (i.e., no ... ; false ) while keeping identical behavior under all possible combinations of argument instantiations - all instantiated, one/two/three completely uninstantiated, and all variations including partially instantiated

JPL/SWI Prolog configuration failure

大兔子大兔子 提交于 2019-11-28 06:13:51
问题 I'm configuring the JPL right now, and wanna work with swi-prolog using java. I downloaded the newest stable version of SWI-Prolog, which is 6.2.0, and installed in D:\swipl First, I added the following path to the PATH virable: D:\swipl\bin, which should include all dll files needed. Then, I added the following path to the CLASSPATH virable: D:swipl\lib\jpl.jar, which should be the jar file needed. When I tried to run the versions example provided, I got the following error: Exception in

How to run SWI-Prolog from the command line?

假如想象 提交于 2019-11-28 02:59:56
问题 Is there a way to just create a prolog script called hello.pl like this: #!/usr/local/bin/swipl -q -s -t main main:- write('Hello World\n'). And be able to run it from the terminal like this? $ hello.pl Hello World $ When I do that it gives me this: hello.pl: line 3: main:-: command not found hello.pl: line 4: syntax error near unexpected token `'Hello World\n'' hello.pl: line 4: ` write('Hello World\n').' I am able to get it working by writing this on the command line: $ swipl -q -f hello.pl

SWI-Prolog - show long list

百般思念 提交于 2019-11-27 05:14:55
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? 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 and the full solution appears in the next line. I've found two ways. 1. ?- set_prolog_flag(answer_write

Read a file line by line in Prolog

独自空忆成欢 提交于 2019-11-27 02:04:11
I'd like to read a plain text file and apply a predicate to each line (the predicates contain write which does the output). How would I do that? In SWI-Prolog, the cleanest solution is to write a DCG that describes what a "line" is, then call a predicate for each line. Use library(pio) to apply the DCG to a file. EDIT : As requested, consider: :- use_module(library(pio)). lines([]) --> call(eos), !. lines([Line|Lines]) --> line(Line), lines(Lines). eos([], []). line([]) --> ( "\n" ; call(eos) ), !. line([L|Ls]) --> [L], line(Ls). Sample usage: ?- phrase_from_file(lines(Ls), 'your_file.txt').