How to remove one fact in CLIPS using C code using factAddress - clips

Retract command in CLIPS will remove one fact in CLIPS.
What is equivalent API in C code.
clips.retract is not working

All C APIs for CLIPS are documented in CLIPS advanced programming guide. Check page 105:
4.4.23 EnvRetract
int EnvRetract(environment,factPtr);
void *environment;
void *factPtr;
Purpose:
Retracts a fact from the CLIPS fact-list (the C equivalent of the
CLIPS retract command).
Hope this answers your question

Related

Is there an official (complete) BNF or EBNF for the CLIPS language

I am looking for an official BNF/EBNF for The CLIPS Programming Language, so that I can write a parser/interpreter that groks (understands) CLIPS rules.
I have searched online, including the official CLIPS documentation, but I have only managed to find sections of the BNF (not the entire BNF).
Does anyone have a source for the COMPLETE (E)BNF for the grammar?
The only BNF available is from Appendix G, CLIPS BNF, of the Basic Programming Guide. That covers all of the constructs and function calls that are not special forms. For special forms (functions that have non-standard syntax such as the fact query functions), the BNF is specified in the section describing that function.

SWI-prolog semweb library processing of URI

Being new to prolog I am reading existing code (as well as trying to write some code). Having some prior background in semweb I started to play with it and see something that is confusing me. Example assertion:
?- rdf_assert(ex:bob, rdf:type, foaf:'Person').
I also did find the following in the documentation:
Remember: Internally, all resources are atoms. The transformations
above are realised at compile-time using rules for goal_expansion/2
provided by the rdf_db library
Am I correct in assuming that somehow the library is treating the three URIs as atoms? I thought that the compiler would treat this as module_name:predicate, but that does not seem to be the case. If that is true, could you please provide a simple example on how this could be done in prolog?
Thanks
Prolog is not a functional language. This implies 2+3 does not evaluate to 5 and is just a term that gets meaning from the predicate that processes it. Likewise, ex:bob is just a term that has no direct relations to modules or
predicates. Only predicates such call/1 will interpret this as "call bob in the module ex".
Next to that, (SWI-)Prolog (most Prolog's, but not all) have term expansion that allows you to rewrite the term that is read before it is handed to the compiler. That is used to rewrite the argument of rdf/3: each appearance of prefix:local is expanded to a full atom. You can check that by using listing/1 on predicates that call rdf/3 using the prefix notation.
See also rdf_meta

Prolog - reload source files

I just finished creating a game in Prolog using Sicstus.
During the game I use assert's and retract's to update the values of some variables I use.
When the game finishes, if I don't reconsult the source files, and re-run the game, those variables have the same content of the past game, which makes sense.
So what I am asking is if exists some sort of built-in predicate that I can call at the end of the game so it reconsults the source files, establishing the original data of the game. (I know it is a lazy way to do it.)
Perhaps you can remove the default facts from the file and write an initializer predicate that asserts them instead. Then you could retract all of them on a restart and rerun your initializer to set the defaults
– lurker
This was the answer.
Thank you Lurker.

How to turn Prolog into preprocessor (kinda m4, gpp)?

m4 can be used with different programming languages because its default policy on unrecognised text is to output and it has a quoting mechanism required for convenient preprocessor usage. I mean, I can write preprocessed code in such a way that my IDE thinks it's Ada. m4 macro invocations (include, define) are hidden in Ada comments. Ada comments start with --, Prolog comments start with % or inside /* */. I can't mix Ada and Prolog easily.
m4 does preprocessing well enough, but its programming side sucks. I thought: why don't me try a general purpose language instead? Prolog looks like being appropriate for my tasks. Prolog has ISO standard, and logic programming looks being useful for reasoning about source generation.
So here we are: we have an arbitrary output language (Ada, then JavaScript, then maybe something else), and it would be nice to write source code in native IDEs for corresponding languages most of the time. I need preprocessor to have a proper parser (like m4 has). This parser shouldn't have Ada syntax knowledge, instead it should only know Ada lexical, and it should be possible to make its macro invocations look like Ada functions invocations.
Its command line interface should look similar to m4 or gcc -E. It should be possible to do both kinds of includes: pure Prolog source code and preprocessed code.
If you know how can I shortly achieve these goals, please write here. I can probably accept non-Prolog solutions, but among the others I prefer standard languages. m4 is part of POSIX, for example.
Prolog is an unusual choice for this task. Indeed, SWI-Prolog used to have the possibility to invoke C preprocessor - should has been removed now, because of its little usefulness.
Anyway, a DCG could be used. I would advice against it if you are not really proficient in Prolog, because debugging can be difficult:
prep(I, O) :-
phrase(exp, I, O).
exp --> mac, !, exp.
exp, [C] --> [C], exp.
exp --> [].
% macro definitions, use 'pushback' argument to change text
mac, "AAA" --> "a".
mac, "G" --> "goal".
example
?- prep("my goal is mars", X).
X = "my G is mAAArs" .
edit: from SWI-Prolog mailing list, WRT the latest release 6.3.18
MODIFIED: Deleted preprocessor/2 after discussion on the
mailinglist. Code relying on this (we hope none) can use the hook
user:prolog_load_file/2 to achieve the same result.
I think the functionality available is more or less that of #include <...>.
For macro expansion (or better, term rewrite) in Prolog there is goal_expansion or term_expansion
edit: latest release brings quasiquotations. Together with a parser in DCG could help to achieve the transformation.
Have you looked at StringTemplate? It's a part of ANTLR (compiler construction toolket). It's written in Java (though there's a C# port, among others). An ANTLR grammar can be written to target many different languages. StringTemplate is what it uses to generate code for the different target languages.
Check it out.
http://antlr.org
http://stringtemplate.org
http://www.cs.usfca.edu/~parrt/
I use DCGs to generate python scripts for FontForge (to create and maintain candlestick fonts for forex trading); I tried M4 scripts but they are not easily amenable to programming (as you mention) and difficult to merge with my glyph definitions that reside in a Prolog database.
DCGs are perceived to be mainly for parsing; but I find they are like a templating engine on their own.

What means (a:b) c and [a:b] c in some Coq theories and where is it defined?

I have seen a very strange syntax: (name:type1) type2 in type and [name:type] expr in expressions, looks like alternate syntax for Pi and Lambda, but I haven't found anything in documentation after several hours of searching, all in vain.
What is it means and where it is defined?
(Sorry I've lost link to example usage)
You've been reading a theory written for an older version of Coq. The syntax got a major rehaul with V8.0. V8.0 shipped with a tool to translate V7 theories into V8, which worked pretty well; the tool was dropped from subsequent releases.
You can see a review of changes in the paper Translation from Coq V7 to V8.
In particular, (a:b) c is a universal quantification, now written forall a:b, c; [a:b] c is a lambda abstraction, now written fun a:b => c. Another important thing when reading old theories is that function application required parentheses and had low precedence: up to V7, (f x = y) meant (f (x=y)) and ([x:nat]y z) meant (([x:nat]y) z).

Resources