iso-prolog

Is it possible to preserve variable names when writing and reading term programatically?

本小妞迷上赌 提交于 2019-12-10 13:28:42
问题 I'm trying to write an SWI-Prolog predicate that applies numbervars/3 to a term's anonymous variables but preserves the user-supplied names of its non-anonymous variables. I eventually plan on adding some kind of hook to term_expansion (or something like that). Example of desired output: ?- TestList=[X,Y,Z,_,_]. > TestList=[X,Y,Z,A,B]. This answer to the question Converting Terms to Atoms preserving variable names in YAP prolog shows how to use read_term to obtain as atoms the names of the

What is the Prolog operator ^?

我与影子孤独终老i 提交于 2019-12-10 03:47:00
问题 What is the Prolog operator ^ ? Looking at The Prolog Built-in Directive op gives a list of the built-in operators. I see ** is exponentiation /\ is or but what is ^ ? Each of the three current answers are of value and I learned something: Roy for the book false for the examples I accepted the answer by CapelliC because it made clear that ^/2 has multiple meanings depending on context which instantly cleared up my confusion. 回答1: In Prolog, most symbols can be used 'uninterpreted', at

Does Prolog have a condition and restart system like Common Lisp?

我与影子孤独终老i 提交于 2019-12-08 20:18:01
问题 Common Lisp allows exception handling through conditions and restarts. In rough terms, when a function throws an exception, the "catcher" can decide how/whether the "thrower" should proceed. Does Prolog offer a similar system? If not, could one be built on top of existing predicates for walking and examining the call stack? 回答1: The ISO/IEC standard of Prolog provides only a very rudimentary exception and error handling mechanism which is - more or less - comparable to what Java offers and

sort/2, keysort/2 vs. samsort/3, predsort/3

隐身守侯 提交于 2019-12-08 14:42:07
问题 ISO-Prolog provides sort/2 and keysort/2 which relies on term order (7.2) often called "standard term order". The common way to sort a list with a different order is to map each element El of that list somehow to a list of pairs XKey-El and then sort that list, and finally project the keys away. As an example consider how keysort/2 can be expressed in terms of sort/2 (See the note for an implementation). In many situations this approach is much faster than using a generic implementation

Equivalent of Python pickling in SWI Prolog?

杀马特。学长 韩版系。学妹 提交于 2019-12-08 02:20:19
问题 I've got a Prolog program where I'm doing some brute force search on all strings up to a certain length. I'm checking which strings match a certain pattern, keeping adding patterns until hopefully I find a set of patterns that covers all strings. I would like to store which ones to a file which don't match any of my patterns, so that when I add a new pattern, I only need to check the leftovers, instead of doing the entire brute force search again. If I were writing this in python, I would

Equivalent of Python pickling in SWI Prolog?

回眸只為那壹抹淺笑 提交于 2019-12-06 13:55:46
I've got a Prolog program where I'm doing some brute force search on all strings up to a certain length. I'm checking which strings match a certain pattern, keeping adding patterns until hopefully I find a set of patterns that covers all strings. I would like to store which ones to a file which don't match any of my patterns, so that when I add a new pattern, I only need to check the leftovers, instead of doing the entire brute force search again. If I were writing this in python, I would just pickle the list of strings, and load it from the file. Does anybody know how to do something similar

Implementing user-defined arithmetic functions

大兔子大兔子 提交于 2019-12-05 10:28:51
How can I add a function (e.g., hammingweight) and use it in expressions occuring in the right-hand side is some (is)/2 goal? Could something like goal_expansion or term_expansion help here? I acknowledge that this is not a big feature, but it could increase readability of some of my Prolog programs. Writing a custom (is)/2 predicate (implementing a custom expression evaluator) is do-able, but I would like to keep runtime overhead low, as I don't want to sacrifice readability for runtime overhead in this case. There is no such provision in ISO Prolog, neither to extend (is)/2 nor to rely on

Prolog DCG set_prolog_flag double_quotes source code directive location matters; documentation?

痴心易碎 提交于 2019-12-05 09:56:22
I learned the hard way that with SWI-Prolog the location for the Prolog directive set_prolog_flag matters in a source code file. The only documentation I found of value about loading source code files with directives was in Loading Prolog source files A directive is an instruction to the compiler. Directives are used to set (predicate) properties (see section 4.15), set flags (see set_prolog_flag/2) and load files (this section). Directives are terms of the form :- <term>. Is there documentation for SWI-Prolog that covers loading of source code that notes if a directive applies to the entire

What is the Prolog operator ^?

≡放荡痞女 提交于 2019-12-05 06:16:54
What is the Prolog operator ^ ? Looking at The Prolog Built-in Directive op gives a list of the built-in operators. I see ** is exponentiation /\ is or but what is ^ ? Each of the three current answers are of value and I learned something: Roy for the book false for the examples I accepted the answer by CapelliC because it made clear that ^/2 has multiple meanings depending on context which instantly cleared up my confusion. In Prolog, most symbols can be used 'uninterpreted', at syntactic level, in particular after a op/3 declaration, any atom can be used as operator . Then you can use, for

Prolog: Clauses are not together in source-file

吃可爱长大的小学妹 提交于 2019-12-03 22:21:44
I have this piece of code: % Family tree female(pen). male(tom). male(bob). female(liz). female(pat). female(ann). male(jim). parent(pam, bob). parent(tom, bob). parent(tom, liz). parent(bob, ann). parent(bob, pat). parent(pat, jim). I get this error: Warning: Clauses of female/1 are not together in source-file Warning: Clauses of male/1 are not together in source-file What is the purpose of this error? I mean, file does compile and run just fine and I am aware of the meaning of the error. But why? Is this just a notice to enforce best practice? I am very new to logic programming. Thanks!