swi-prolog

Querying from the terminal doesn't print anything

半城伤御伤魂 提交于 2019-12-23 13:02:05
问题 When ran in the command line, this swipl -g "write(42)" -t "halt" prints 42 to STDOUT as expected. However, this swipl -g "X = 42" -t "halt" does not print anything, it simply returns. How do I get it to print what it prints in the REPL (that is, X = 42 )? Note: this is in a Windows terminal. Let me know if this actually works in a Linux terminal. 回答1: As expected, X = 42 by itself produces no output whatsoever , because (=)/2 is a completely pure predicate that does not yield any side

Define parts of a predicate across several modules

我的梦境 提交于 2019-12-23 12:47:22
问题 I'm trying to write a predicate move/3 which handles several kinds of terms, each kind of which is defined in a separate file. I'm trying to use modules for this, because the files contain other predicates which should be namespaced appropriately. So, I've created a module cat.prolog with contents: :- module(cat, [move/3]). :- multifile(move/3). move(cat(C), P, cat(C2)) :- ... Similarly for dog.prolog . And main.prolog with: :- use_module(['cat.prolog'], [move/3]). :- use_module(['dog.prolog'

How do I show the results of pattern-matching goals in SWI-Prolog from a shell invocation?

眉间皱痕 提交于 2019-12-22 12:38:36
问题 I am wondering how one gets output from SWI-Prolog when invoking it from the shell. Say I have a simple knowledge base, kb.pl : dad(elvis, lisaMarie). dad(john, julian). I can invoke SWI-Prolog from the shell: $ swipl --quiet -s kb.pl -t listing and a listing of my knowledge base is printed to stdout . If I try this: $ swipl --quiet -s kb.pl -t "dad(elvis, X)" $ echo $? 0 No output is printed, but I know that it found matches because I get zero when I then query for the return code. Similarly

How to enable GMP on freebsd?

最后都变了- 提交于 2019-12-22 10:58:33
问题 I installed swi-prolog as below: $./configure --prefix=/home/***/swi-prolog/ --enable-gmp $gmake && gmake check && gmake install however, it still reports no GMP syupport: ?- random(33). Warning: This version of SWI-Prolog is not compiled with GMP support. Warning: Floating point random operations are not supported. ERROR: is/2: Arithmetic: `random_float/0' is not a functionenter code here $find /usr/local/lib -name "libgmp*" /usr/local/lib/libgmp.so.10 /usr/local/lib/libgmp.so /usr/local/lib

catch/3 and call_with_time_limit/2 predicates in SWI-Prolog

北慕城南 提交于 2019-12-22 04:35:47
问题 I want to use catch(:Goal, +Catcher, :Recover) where Goal is call_with_time_limit(+Time, :Goal) It's messed up and I can't find the right way to know when one of the above happened: 1) Goal stopped because of time out. 2) Goal failed (it's suppose to fail sometimes). I tried: (catch(call_with_time_limit(Time, Goal), Catcher, Recover) -> (ground(Catcher), Catcher = time_limit_exceeded), **TIMEOUT ACTIONS**) ; (**SUCCESS ACTIONS**)) ; **FAILURE ACTIONS** ) * EDIT * Pattern: I use the following

swi prolog mysql + web

☆樱花仙子☆ 提交于 2019-12-21 21:36:23
问题 Sorry for my English. I want to create a simple website that will take data from the mysql database and display it on the page. I have two problems: 1) work with a database made in separate modules: % database.pl :- module(database, [ create_db_connect/0, use_database/0, query_to_database/1, disconnect_database/0 ]). :- use_module(library(odbc)). create_db_connect :- odbc_connect('test', _, [ user('root'), password('123') alias(myblog), open(once) ]). use_database :- odbc_query(myblog, 'use

How to query RDF/OWL using SWI-Prolog's Semantic Web Library?

泪湿孤枕 提交于 2019-12-20 12:35:58
问题 How can I use the SWI-Prolog Semantic Web Library to make a query into the OWL/RDF file and extract some information? The OWL/RDF file is having information about all the Debian packages so I need to make the query in order to find package dependencies. For Example: The OWL file is structured as follows: package: A Depends: package: B pacakge: C How can I load a OWL/RDF file into a Prolog script and what is the syntax to make a query within the Prolog script such that I put A as a parameter

Using aleph with SWI-prolog: source_sink `library(aleph)' does not exist

坚强是说给别人听的谎言 提交于 2019-12-20 07:18:10
问题 I’m trying to work Aleph with Swi-prolog. When I ran my program I got the error here. What can I do to import the library(aleph)?By the way, I have already downloaded Aleph.pl for my program. Here is my test program, I know there must be something wrong with the library aleph. :- use_module(library(aleph)). :- aleph. I got the error: ERROR: c:/users/mac/desktop/swi-prolog/aleph draft/1.pl:1: source_sink `library(aleph)' does not exist Warning: c:/users/mac/desktop/swi-prolog/aleph draft/1.pl

json get prolog predicate

删除回忆录丶 提交于 2019-12-20 05:00:24
问题 I'm tryung to create this predicate in prolog: The predicate json_get/3 can be defined as: json_get(JSON_obj, Fields, Result). which is true when Result is recoverable by following the chain of fields in Fields (a list) starting from JSON_obj . A field represented by N (with N a major number o equal to 0) corresponds to an index of a JSON array. Please help me to understand to follow the chain of fields. Thanks edit1: Of course, so json object looks like this '{"name" : "Aretha", "surname" :

Generating subsets using length/2 and ord_subset/2

我的未来我决定 提交于 2019-12-20 04:32:40
问题 I am a beginner in prolog. I tried this in swipl interpreter: ?- length(Lists, 3), ord_subset(Lists, [1, 2, 3, 4]). false. expecting to get all length-3 lists that are subsets of [1, 2, 3, 4] like [1, 2, 3] or [1, 2, 4]. Why do i get false? Notice: both length and ord_subset are builtin functions (or whatever they are called) in SWI-Prolog. 回答1: You don't get a solution because the ord_subset/2 predicate only checks if a list is a subset of another list; it does not generate subsets. Here is