2017-03-17 5 views
0

ich in this lesen SO antworten, dass esCLIPS eine Eigenschaft einer Eigenschaft Zugriff auf

better to explicitly retrieve the slot value by matching it rather than using the slot accessor as this will cause the condition to be reevaluated whenever the slot value changes

ist Was passiert, wenn ich die Eigenschaft einer Eigenschaft zugreifen möchten? Zum Beispiel

gegeben zwei Instanzen a und b der Klassen A bzw. B.

a hat eine Eigenschaft namens ref_to_b, die eine Referenz auf b ist. b hat eine Eigenschaft namens some_prop_of_b.

Wie ich folgendes passen:

a mit ref_to_b gleich b und some_prop_of_b gleich "some_string".

habe ich versucht, diese bekam aber einen Fehler:

(defrule my_rule "comment me" 
    (object (is-a A) 
     (ref_to_b ?ref_to_b)) 
    (?ref_to_b 
     (some_prop_of_b "some_string")) 
=> 
) 

Antwort

1

Platz der Instanzname der referenzierten Instanz im ref_to_b Schlitz und dann den Namen Steckplatz verwenden, um die Referenz anzupassen:

CLIPS> 
(defclass A (is-a USER) (slot ref_to_b)) 
CLIPS> 
(defclass B (is-a USER) (slot some_prop_of_b)) 
CLIPS> 
(make-instance [b1] of B (some_prop_of_b "some_string")) 
[b1] 
CLIPS> 
(make-instance [b2] of B (some_prop_of_b "not_some_string")) 
[b2] 
CLIPS> 
(make-instance [a] of A (ref_to_b [b2])) 
[a] 
CLIPS> 
(defrule my_rule 
    (object (is-a A) (ref_to_b ?name_b)) 
    (object (name ?name_b) (some_prop_of_b "some_string")) 
    =>) 
CLIPS> (agenda) 
CLIPS> (send [a] put-ref_to_b [b1]) 
[b1] 
CLIPS> (agenda) 
0  my_rule: [a],[b1] 
For a total of 1 activation. 
CLIPS> 
+0

Ah die Name Slot. Das war der Schlüssel. – stackoverflowwww

Verwandte Themen