I would like to embedd an instance [a] of class A in an instance [b] of Class B and access [a] from [b]. But I haven't find a way !
(make-instance) returns the instance-name ; how can I reach the instance itself ?
CLIPS> (defclass A (is-a USER) (role concrete))
CLIPS> (defclass B (is-a USER) (role concrete)
(slot A
(type INSTANCE)
(allowed-classes A)
(default ?NONE)
)
)
CLIPS> (make-instance of B (A (make-instance of A)))
CLIPS> (instances)
[initial-object] of INITIAL-OBJECT
[gen1] of B
[gen2] of A
For a total of 3 instances.
CLIPS> (send [gen1] print)
[gen1] of B
(A [gen2])
CLIPS> (send [gen1]:A print)
[MSGFUN1] No applicable primary message-handlers found for print.
FALSE
CLIPS> (send [gen2] print)
[gen2] of A
CLIPS> (class [gen1])
B
CLIPS> (class [gen1]:A)
SYMBOL
CLIPS>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Short hand slot references work with variables in appropriate situations (such as ?self:A in a message-handler). The syntax you've used to retrieve a slot from an instance name, [gen1]:A, is not supported. Use (send [gen1] get-A) instead. If you do want to convert an instance name to an instance address, use the instance-address function.
CLIPS> (defclass A (is-a USER) (role concrete))
CLIPS>
(defclass B (is-a USER) (role concrete)
(slot A
(type INSTANCE)
(allowed-classes A)
(default ?NONE)))
CLIPS> (make-instance of B (A (make-instance of A)))
[gen1]
CLIPS> (instances)
[initial-object] of INITIAL-OBJECT
[gen1] of B
[gen2] of A
For a total of 3 instances.
CLIPS> (send [gen1] print)
[gen1] of B
(A [gen2])
CLIPS> (send (send [gen1] get-A) print)
[gen2] of A
CLIPS> (send [gen2] print)
[gen2] of A
CLIPS> (class [gen1])
B
CLIPS> (class (send [gen1] get-A))
A
CLIPS> (instance-address [gen2])
<Instance-gen2>
CLIPS> (instance-address [gen1])
<Instance-gen1>
CLIPS>
Last edit: Gary Riley 2013-06-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to embedd an instance [a] of class A in an instance [b] of Class B and access [a] from [b]. But I haven't find a way !
(make-instance) returns the instance-name ; how can I reach the instance itself ?
Short hand slot references work with variables in appropriate situations (such as ?self:A in a message-handler). The syntax you've used to retrieve a slot from an instance name, [gen1]:A, is not supported. Use (send [gen1] get-A) instead. If you do want to convert an instance name to an instance address, use the instance-address function.
Last edit: Gary Riley 2013-06-04
Thank you Gary,
I had seen this syntax in examples not in the reference manual.
I understand that it is better to avoid it!