swi-prolog

Opening and checking a Pem file in SWI-Prolog

◇◆丶佛笑我妖孽 提交于 2019-12-10 17:14:50
问题 How do I open a Pem file to check a) That the 'Not before' and 'Not after' dates are okay and b) That there is a chain of certs in the pem file to a route certificate authority? I have tried: :-use_module(library(http/http_client)). url('http://fm4dd.com/openssl/source/PEM/certs/512b-rsa-example-cert.pem'). url_data(Url,D):- http_get(Url,D,[to(string)]). url_data1(Url,Certificate):- http_get(Url,D,[to(stream(Stream))]), load_certificate(Stream, Certificate), close(Stream). url_data/1 works in

Why a clpfd variable is assigned to an actual value in a reification?

穿精又带淫゛_ 提交于 2019-12-10 16:38:58
问题 I'm working on a (SWI-)Prolog program that uses CLP(FD) constraints to find a solution for a particular problem. To do so, I happen to need what I call an "unpositioned" overlapping of two lists. That is: List La has length A List Lb has length B A > B The unpositioned overlapping list is La+Lb , where elements are added in a one-by-one fashion. However, I need Lb to have a variable offset (i.e. each lists' first element are not in the same position for the La+Lb addition. However, list Lb is

What's the difference between “false” and “no” in Prolog

房东的猫 提交于 2019-12-10 14:47:21
问题 I started to learn Prolog following the book Programming in Prolog: Using the ISO Standard. At page 7 of the intro to the language they made the assertion : "In Prolog the answer no is used to mean nothing unifies with the question . It is important to remember that no is not the same as false ". So why SWI-Prolog uses the false and true statement instead of yes or no ? 回答1: To begin with, the ISO standard (ISO/IEC 13211-1:1995) does not define a toplevel loop. In 1 Scope it reads: NOTE —

Random items in Prolog

南笙酒味 提交于 2019-12-10 14:33:18
问题 I know I can do X is random(10). to get a random number from 0 to 10, but is there a similar command to get a random matching item? 回答1: You can implement it. Here is a version: %% choose(List, Elt) - chooses a random element %% in List and unifies it with Elt. choose([], []). choose(List, Elt) :- length(List, Length), random(0, Length, Index), nth0(Index, List, Elt). From http://ozone.wordpress.com/2006/02/22/little-prolog-challenge/ 回答2: SWI-Prolog v6 has random_member/2 defined like this:

Implementing XOR function with Prolog CLPFD for 32-bit numbers

醉酒当歌 提交于 2019-12-10 13:26:11
问题 I try to implement efficient exclusive-or (XOR) in Prolog CLPFD. This should be simple predicate like: xor(A, B, AxorB). A , B , AxorB are natural numbers (with 0) and AxorB is a result of A xor B . My main problem is with efficiency. Firstly, I wasn't able to find any way to XOR two number without breaking those numbers into separate parts that could be further processed/constrained, and the process of breaking those numbers (creating proper constraints and then resolving them) is taking

How to parameterize a SPARQL query in SWI Prolog?

偶尔善良 提交于 2019-12-10 11:42:10
问题 I am having difficulty making the following SPARQL query parametric. First I load the request library: ?- use_module(library(semweb/sparql_client)). % library(uri) compiled into uri 0.02 sec, 290,256 bytes % library(readutil) compiled into read_util 0.00 sec, 17,464 bytes % library(socket) compiled into socket 0.00 sec, 11,936 bytes % library(option) compiled into swi_option 0.00 sec, 14,288 bytes % library(base64) compiled into base64 0.00 sec, 17,912 bytes % library(debug) compiled into

Reading a string (from a file) in Prolog

谁都会走 提交于 2019-12-10 10:29:07
问题 I have written a lexer and a parser in Prolog. It unifies a string with its AST. This is part for a compiler/interpreter project I am working on. Naturally, I now want to read the string from a file to parse it. However, the predicates I have found for this is read , and it only reads Prolog atoms and predicates, like files with hello. I have been twiddling with the double_quotes settings, but with no success. I want to be able to read a file with something like this let id = \x.x in id (S (S

Embedding SWI-Prolog in a dll

南笙酒味 提交于 2019-12-09 21:12:35
问题 I'm building a C++ library (windows, DLL) and I'd like to embed swi-prolog for some functionalities. What I'm doing is: #include <Windows.h> #include <SWI-Prolog.h> BOOL WINAPI DllMain( HINSTANCE hinstDLL, // DLL モジュールのハンドル DWORD fdwReason, // 関数を呼び出す理由 LPVOID lpvReserved // 予約済み ) { BOOL result = TRUE; switch(fdwReason) { case DLL_PROCESS_ATTACH: { char* av[]{"libswipl.dll"}; _putenv(R"(SWI_HOME_DIR=C:\Program Files (x86)\swipl\)"); if(!PL_initialise(1, av)) { result = TRUE; } else { PL_halt

Prolog - DCG parser with input from file

强颜欢笑 提交于 2019-12-09 16:12:06
问题 As part of a project I need to write a parser that can read a file and parse into facts I can use in my program. The file structure looks as follows: property = { el1 , el2 , ... }. What I want in the end is: property(el1). property(el2). ... I read my file like this: main :- open('myFile.txt', read, Str), read_file(Str,Lines), close(Str), write(Lines), nl. read_file(Stream,[]) :- at_end_of_stream(Stream). read_file(Stream,[X|L]) :- \+ at_end_of_stream(Stream), read(Stream,X), parse(X), %

How to Interfacing SWI Prolog to the Visual Studio 2012

最后都变了- 提交于 2019-12-08 21:42:53
问题 I have a program that interfacing SWI-Prolog in Visual Studio. Previously, I used VS2010 (XP) and everything works fine. Then I upgrade my VS to become VS2012 (Win7) and now I have a problem in my code. When it comes to the following code: PlEngine.Initialize(param); it always gives me the following exception message: The specified module could not be found. (Exception from HRESULT: 0x8007007E) Can anybody spot what mistake that I made or if possible some modification that I have to do, due