Homunculus Reticulli
Homunculus Reticulli

Reputation: 68466

CLIPS - multislot field using deftemplate: Syntax error for type attribute

I am using CLIPS 6.4 and I have the ff code:

(deftemplate feature
   (slot name (type SYMBOL))
   (slot description (type STRING)))

(deftemplate car
   (slot make (type SYMBOL))
   (slot model (type SYMBOL))
   (multislot features (type feature)))

When I paste it into CLIPS console, I get the error:

[PRNTUTIL2] Syntax Error: Check appropriate syntax for type attribute.

How can I nest deftemplates in this manner?

Upvotes: 0

Views: 102

Answers (2)

Gary Riley
Gary Riley

Reputation: 10757

You can't nest deftemplates. As the other answer indicates, you can store a fact-address within one fact to reference another, but since each feature has a symbolic name, use that instead to reference the feature from the car.

CLIPS> 
(deftemplate feature
   (slot name (type SYMBOL))
   (slot description (type STRING)))
CLIPS> 
(deftemplate car
   (slot make (type SYMBOL))
   (slot model (type SYMBOL))
   (multislot features (type SYMBOL)))
CLIPS>    
(deffacts features
   (feature (name leather-seats)
            (description "leather seats"))
   (feature (name sunroof)
            (description "sun roof"))
   (feature (name heated-seats)
            (description "heated seats"))
   (feature (name backup-camera)
            (description "backup camera"))
   (feature (name navigation-system)
            (description "navigation system")))
CLIPS> 
(deffacts cars
   (car (make Hyundai)
        (model Accent)
        (features heated-seats))
   (car (make Honda)
        (model Accord)
        (features sunroof backup-camera))
   (car (make Nissan)
        (model Altima)
        (features navigation-system heated-seats leather-seats))
   (car (make Chevrolet)
        (model Blazer)
        (features leather-seats sunroof backup-camera navigation-system))
   (car (make Toyota)
        (model Camry)
        (features navigation-system heated-seats)))
CLIPS>         
 (defrule car-has-heated-seats
    (car (make ?make)
         (model ?model)
         (features $? heated-seats $?))
    (feature (name heated-seats)
             (description ?description))
    =>
    (println ?make " " ?model " has " ?description "."))
CLIPS> (reset)
CLIPS> (run)
Toyota Camry has heated seats.
Nissan Altima has heated seats.
Hyundai Accent has heated seats.
CLIPS> 

Upvotes: 1

noxdafox
noxdafox

Reputation: 15060

A deftemplate cannot be used to infer a type. For a multifield of facts, you can restrict the value using the FACT-ADDRESS type.

(deftemplate feature
   (slot name (type SYMBOL))
   (slot description (type STRING)))

(deftemplate car
   (slot make (type SYMBOL))
   (slot model (type SYMBOL))
   (multislot features (type FACT-ADDRESS)))

Upvotes: 1

Related Questions