I am using CLIPS for knowledge base systems, but I am facing a problem with understanding the following three types:
1- external-address
2- instance-name
3- instance-address
I read the following:
external-address: address of external data structure returned by user-defined function (written in a language such as C or Jave) that has been integrated with CLIPS
I couldn't understand it, is there an Example for this ?
instance-name: is formed by enclosing a symbol within left and right bracket, Thus pure symbols may not be surrounded by brackets
okay, I understand that they are brackets around symbols but what is the use of them ? is there any example?
also, I need an example for instance-address
An external address is a pointer to memory that is not managed by CLIPS. The only way to create an external address is to use the user-defined function API in CLIPS to call out to a function which returns a pointer to memory. The default value for an external address is a null pointer, so if you declare the type of a slot to be an external-address, and don't specify the value when you assert a fact, you'll see the value of the slot set to a null pointer.
CLIPS> (deftemplate window (slot pointer (type EXTERNAL-ADDRESS)))
CLIPS> (assert (window))
<Fact-1>
CLIPS> (facts)
f-1 (window (pointer <Pointer-C-0x0>))
For a total of 1 fact.
CLIPS>
If you wanted to create a GUI that could be manipulated by CLIPS, you might define some user-defined functions which allocate a window (create-window) and print to that window (print-window). You could then create a window and assign the pointer to the slot value of a fact:
(assert (window (pointer (create-window))))
You could then print to the window from a rule like this:
(defrule hello
(window (pointer ?window))
=>
(print-window ?window "Hello World!"))
Fact-addresses and instance-addresses are also pointers to memory, but these are pointers to data structures that CLIPS maintains.
An instance name is just a special kind of symbol that refers to an instance of a class. You can specify the instance name when creating an instance or, if none is specified, one will be automatically created. Messages can be sent to an instance using either the instance name or the instance address.
CLIPS> (defclass POINT (is-a USER) (slot x) (slot y))
CLIPS> (make-instance [p1] of POINT (x 1) (y 2))
[p1]
CLIPS> (make-instance of POINT (x 0) (y 3))
[gen1]
CLIPS> (instances)
[p1] of POINT
[gen1] of POINT
For a total of 2 instances.
CLIPS> (send [p1] get-x)
1
CLIPS> (instance-address [p1])
<Instance-p1>
CLIPS>
(defrule example
?i <- (object (is-a POINT) (name ?n))
=>
(println "The instance address is " ?i)
(println "The instance name is " ?n))
CLIPS> (run)
The instance address is <Instance-gen1>
The instance name is [gen1]
The instance address is <Instance-p1>
The instance name is [p1]
CLIPS>