3 ms·
CLIPS: An Elevator Pitch
- Rochus 2y agoWhat about performance for the recommended application? CLIPS is fully interpreted, isn't it?
- ryjo 2y agoYou can compile CLIPS (including your rules) into C code from within CLIPS itself, which then gets compiled to a dedicated binary.
- Rochus 2y agoDo you mean the "constructs-to-c"? But does this actually give a speed-up?
- ryjo 2y ago> Do you mean the "constructs-to-c"? Yes > But does this actually give a speed-up? There is an objective benefit to using `constructs-to-c` and that is something you mention in your original comment: you generate a single binary file containing all of your business logic, thus avoiding running a "fully interpreted" app in production. In order to determine if it gives a performance boost to your particular rules engine, you should test it out and benchmark it with something you'd consider a "real world" example.
- Rochus 2y ago> you should test it out and benchmark it with something you'd consider a "real world" example. I thought that you might have specific experience with "real world" applications, thus my question. The CLIPS "Advanced Programming Guide" states in secion 11.1, that "...compiles all of the constructs [..] into a single executable and reduces the size of the executable image. A run-time program will not run any faster than a program loaded using the load or bload commands"; so as far as I understand it, the code is still interpreted (i.e. not affected by the translation to C).
- ryjo 2y agoGood find in the apg! That thing is a wealth of info. It look like contructs-to-c wouldn't make things faster, but would instead reduce the compiled code size. If I'm understanding your meaning, you mean "interpreted" in a sense that it translates to C code, and C code is interpreted and translated into machine code. Is that accurate? It's possible that you and I are referring to different things when we use the word "interpreted." When I think "interpreted" in the context of computer programming, I'm thinking in terms of interpreted-at-runtime programming languages like Ruby, Python, and CLIPS before you use `constructs-to-c`. In my mind, using `constructs-to-c` changes this from an "interpreted" to a "compiled" language in that the expert system you write in CLIPS code is its own language with its own data structures, algorithms, and DSL. When you use `constructs-to-c`, you "compile" your application using the programming language of your expert system, thus it is no longer interpreted at run time.
- Rochus 2y ago> you mean "interpreted" in a sense that it translates to C code, and C code is interpreted and translated into machine code No, I mean that the Lisp variant of CLIPS is a pure interpreter, (assumingly) not even threaded, and (certainly) no JIT. The "constructs-to-c" feature apparently doesn't change anything to that, i.e. even in the "translated to C" version of the CLIPS code it is still interpreted. > I'm thinking in terms of interpreted-at-runtime programming languages like Ruby, Python Me too. > and CLIPS before you use `constructs-to-c` ... changes this from an "interpreted" to a "compiled" language Didn't find evidence for this so far; as far as I understand it's still the same interpreter.
- ryjo 2y agoI'm sorry, but I still think I'm not sure what you mean by interpreter. I hope you don't mind if I press further, but I'm very much enjoying this deep dive into the CLIPS C API with you. When you compile your code including the c files generated by the constructs-to-c command, you must update the main.c file as well as the makefile that ships with CLIPS. During that update, there are a few things you must do: 1. add the generated c files to the makefile 2. you remove the function calls in the main.c file that cause CLIPS to capture STDIN and STDOUT. That is: you remove one layer of abstraction that sits between your rules and i/o streams. 3. you remove the generic CreateEnvironment function call in main.c and replace it with InitCImage_1, a function that calls CreateRuntimeEnvironment. CreateRuntimeEnvironment differs from CreateEnvironment because you are able to pass in pre-built: 1. symbolTable 2. floatTable 3. integerTable 4. bitmapTable Which are your rules engine constructs represented in C. In addition to these four things, CreateRuntimeEnvironment passes in functions the user may have defined as UserDefinedFunctions (UDFs) in C. This is a more direct path than having CLIPS first interpret CLIPS rules like `(defrule foo =>)` and then translate them into these C representations.