Retrieving Slot Names for a Multislot Field from CLIPS through C/C++.

321 views
Skip to first unread message

Aashu

unread,
Mar 15, 2012, 2:18:13 PM3/15/12
to CLIPSESG
Hi All,

I need to fetch the Slot Names from CLIPS for a Multislot Field (which
is a part of a USER defined class) from C/C++ code.
I tried to use EnvSend/a sample deffunction which prints the Slot
Names, but none of them produced the desired result, might be I am
missing something.

So is there any way through which I can retrieve the Slot Names/Values
for a MultiSlot.

Eg:

(defclass Card (is-a USER)
(role concrete)
(pattern-match reactive)
( slot CardNumber (type STRING) )
( multislot InfoList (type INSTANCE) )
)

(defclass CardInfo (is-a USER)
(role concrete)
(pattern-match reactive)
( slot BinRange (type STRING) )
)


(defrule Abc
?card<-(object (is-a Card)(CardNumber ?card.CardNumber))
(test (starts-with ?card.CardNumber "AT2"))
=>
(make-instance [cardinfo] of CardInfo)

(slot-insert$ ?card InfoList (+ 1 (length$ (send ?card get-InfoList)))
(instance-address [cardinfo]))

)

Now I need to have some output through C function which returns like
this, which has both Class Name and Object Names in that Multislot.

(send [Instance of Card] print)

or,

[Instance of Card Class i.e. card1] of Card
(CardNumber "AT210000001234")
(Card CardInfo<Instance-Name of CardInfo class Object1 i.e. cardinfo>
ClassName2<Instance-Name of class Object2>)


Any guidance in this matter would be appreciated.

Artem Novikov

unread,
Mar 17, 2012, 9:15:17 AM3/17/12
to clip...@googlegroups.com
1. Using stdout router

C++
-------------
CPPClips::CPPClips()
{
...
EnvAddRouter(theEnv, "ClipsIO", 10, queryRouter, printRouter, NULL, NULL, NULL);
...
}

int CPPClips::queryRouter(void*, char* name) // logicalName
{
if (!qstrcmp(name, STDOUT) ||
return true;

return false;
}

static int printRouter(void* theEnv, char* name, char* str) { // process *str }


CLIPS
-------------
(defmessage-handler CardInfo Print ()
(printout t ?self (instance-name ?self))) ; <- to printRouter(..., str)


2. Using defined function

C++
-------------
CPPClips::CPPClips()
{
...
EnvDefineFunction2(theEnv, "cppFunc", 'v', cppFunction, "cppFunction", "34");
...
}

int CPPClips::cppFunction(void* theEnv) //void *theEnv
{
  if (RtnArgCount() == 4) 
...

RtnLexeme(1)
RtnLexeme(N)
}

CLIPS
-------------
(defmessage-handler CardInfo Print ()
(cppFunc ?self (instance-name ?self))) ; <- to cppFunction(Lexem_1, ...)


пятница, 16 марта 2012 г. 2:18:13 UTC+8 пользователь Aashu написал:

Artem Novikov

unread,
Mar 17, 2012, 9:37:26 AM3/17/12
to clip...@googlegroups.com
P.S.
See APG 
3.2.4 Passing Multifield Values  
Reply all
Reply to author
Forward
0 new messages