gnu-prolog

How to use a “long int” in GNU Prolog?

眉间皱痕 提交于 2020-01-04 09:03:58
问题 So basically it seems that GNU Prolog use 28bit integer on my 32bit x86 Linux. The code below can not be compiled: foo(A) :- A0 is 0xdeadbeef, A1 is A0 >> 8, A2 is A0 >> 16, A3 is A0 >> 24. Then I am confused with two typical situations below: How to represent a 32bit integer in GNU Prolog (like 0xdeadbeef)? and pushing it further, how to represent a 64 bit integer ? On 64 bit x86 Linux, long long type in C has 64 bit. When using GNU Prolog to call C, the interface defined in the manual has

How to use a “long int” in GNU Prolog?

此生再无相见时 提交于 2020-01-04 09:03:29
问题 So basically it seems that GNU Prolog use 28bit integer on my 32bit x86 Linux. The code below can not be compiled: foo(A) :- A0 is 0xdeadbeef, A1 is A0 >> 8, A2 is A0 >> 16, A3 is A0 >> 24. Then I am confused with two typical situations below: How to represent a 32bit integer in GNU Prolog (like 0xdeadbeef)? and pushing it further, how to represent a 64 bit integer ? On 64 bit x86 Linux, long long type in C has 64 bit. When using GNU Prolog to call C, the interface defined in the manual has

How to use a “long int” in GNU Prolog?

假装没事ソ 提交于 2020-01-04 09:03:12
问题 So basically it seems that GNU Prolog use 28bit integer on my 32bit x86 Linux. The code below can not be compiled: foo(A) :- A0 is 0xdeadbeef, A1 is A0 >> 8, A2 is A0 >> 16, A3 is A0 >> 24. Then I am confused with two typical situations below: How to represent a 32bit integer in GNU Prolog (like 0xdeadbeef)? and pushing it further, how to represent a 64 bit integer ? On 64 bit x86 Linux, long long type in C has 64 bit. When using GNU Prolog to call C, the interface defined in the manual has

Prolog: how to do “check(a++b++c++d equals d++a++c++b) -> yes”

拟墨画扇 提交于 2020-01-01 12:05:29
问题 Let's define custom operators - let it be ++ , equals :- op(900, yfx, equals). :- op(800, xfy, ++). And fact: check(A equals A). I try to make predicate, let it be check/1 , that will return true in all following situations: check( a ++ b ++ c ++ d equals c ++ d ++ b ++ a ), check( a ++ b ++ c ++ d equals d ++ a ++ c ++ b), check( a ++ b ++ c ++ d equals d ++ b ++ c ++ a ), % and all permutations... of any amount of atoms check( a ++ ( b ++ c ) equals (c ++ a) ++ b), % be resistant to any

GNU Prolog assert error

ⅰ亾dé卋堺 提交于 2019-12-28 06:59:06
问题 I am new to Prolog, but I am stuck at this supposedly simple command. I have loaded a knowledge base with no errors, and whenever I try do assert (and even help ) I get the following message: uncaught exception: error(existence_error(procedure,assert/1),top_level/0) {2} What am I exactly missing? Appreciated. 回答1: Use assertz/1 or asserta/1 instead. GNU-Prolog does not provide assert/1 because only asserta/1 and assertz/1 are defined in the standard. Note that while asserta/1 always had one

gprolog - Simple way to determine whether one list is a permutation of another

…衆ロ難τιáo~ 提交于 2019-12-24 05:33:37
问题 I'm trying to write a prolog program that determines whether one list is a permutation of another. Input is of the form perm(L,M) , which will be true if and only if list L is a permutation of list M . This is for my AI class, so I cannot just use the nifty little permutation predicate that gprolog already provides. Our professor noted that the member predicate might be useful, but any ideas I have that involve it seem to require very tricky and not-so-declarative things (and I'm assuming

Problem with `\+` in Prolog queries with variables

白昼怎懂夜的黑 提交于 2019-12-22 06:35:45
问题 I'm reading "Seven languages in seven weeks" atm, and I'm stumped over some Prolog query that I don't understand the 'no' response to. The friends.pl file looks like this: likes(wallace, cheese). likes(grommit, cheese). likes(wendolene, sheep). friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z). I can do some trivial queries on it, such as: | ?- ['friends']. compiling /home/marc/btlang-code/code/prolog/friends.pl for byte code... /home/marc/btlang-code/code/prolog/friends.pl compiled, 12

Is it possible to get these memory addresses in gnu prolog?

…衆ロ難τιáo~ 提交于 2019-12-13 23:45:24
问题 Basically I am trying to simulate C pointer dereference using gnu-prolog. Here is the code: Prolog :-foreign(fun(+integer,-integer)). % p = &b; testfun(Var, Val) :- fun(Val, Var). main :- A is 1, testfun(A, P), write(P), C: #include <gprolog.h> #include <string.h> PlBool fun(int ptr, int* res){ *res = &ptr; // this is wrong if(res==NULL){ return PL_FALSE; }else{ return PL_TRUE; } } So basically it is wrong, because ptr is just a temp variable on the stack, and its memory will be deallocated

How to use read_line_to_codes & atom_codes iteratively to generate array of lines as strings of my .txt file?

喜你入骨 提交于 2019-12-13 04:44:41
问题 I am trying to use read_line_to_codes(Stream,Result) and atom_codes(String,Result) . These two predicates first, read line from file as an array of char codes, and then convert this array back to string. Then I would like to input all those strings to an array of Strings. I tried the recursive approach but have trouble with how to actually instantiate the array to empty in the beginning, and what would be the terminating condition of process_the_stream/2 . /*The code which doesn't work.. but

Reading a line from a file in GNU Prolog

做~自己de王妃 提交于 2019-12-11 14:08:27
问题 I feel like I'm bashing my head against a wall with something that I assume should be easy. Perhaps my approach is incorrect. I definitely don't feel like I understand the concept behind I/O in Prolog. (Such as: what is the difference between a stream alias and the variable bound by open/3?) But I digress: How do a read a file line-by-line in GNU Prolog? (So without access to the handy functions that SWI has.) I assume it has something to do with get_char/1 and peek_char/1 (to check for a