:objects

<-Previous | ^UP^ | Next->

In the Getting Started with GendL tutorial, the Defining Objects topic covered the general syntax for defining objects. In that topic we covered :input-slots, :computed-slots, :functions and :objects. In the previous topic we also covered :trickle-down-slots. In this topic we will look at :hidden-objects and the :pseudo-inputs input to both :objects and :hidden-objects

:hidden-objects

We actually introduced :hidden-objects in the Truss Example topic of the Getting Started with GendL tutorial

The most obvious outcome of using :hidden-objects is that child objects defined in this way don't show up in the Geysr tree structure. However there are other effects

  • :hidden-objects are omitted from the list returned by (list-elements (the))
  • :hidden-objects are not included in the messages (the children) or (the safe-children)
:hidden-objects, however, can be accessed using referencing chains in exactly the same way that a normal child obejct is referenced. To list all hidden-objects we need to use the message (the hidden-children)
(define-object hidden-objects (base-object):computed-slots((box-volume (the (my-box 0) volume))(hidden-box-volume (the (my-hidden-box 0) volume))(object-list (list-elements (the)))(all-objects (append (the children)(the hidden-children)))):objects((my-box :type 'box:length 2:width 2:height 2:sequence (:size 3))):hidden-objects((my-hidden-box :type 'box:length 3:width 3:height 3:sequence (:size 2))))

GDL-USER> (make-self 'hidden-objects)

#<HIDDEN-OBJECTS #x21043FB8BD>

GDL-USER> (the box-volume)

8

GDL-USER> (the hidden-box-volume)

27

GDL-USER> (the children)

(#<BOX #x21044894DD> #<BOX #x210448B6ED> #<BOX #x210448B2CD>)

GDL-USER> (object-list)

(#<BOX #x21044894DD> #<BOX #x210448B6ED> #<BOX #x210448B2CD>)

GDL-USER> (the hidden-children)

(#<BOX #x21044876DD> #<BOX #x2104494BAD>)

GDL-USER> (the all-objects)

(#<BOX #x21044894DD> #<BOX #x210448B6ED> #<BOX #x210448B2CD>) #<BOX #x21044876DD> #<BOX #x2104494BAD>)

:pseudo-inputs

:pseudo-inputs enable us to pass a value into an object without the slot being defined as an :input-slot. This may seem a curious requirement, as if its not defined as an :input-slot we won't be able to use it in :computed-slots or pass forn to further child :objects. But it actually turns out to be really usefl if we want to make a slight customisation to an object without needing to define a new object. It may be that we wish to perform a calculation and attach the value to that object, or simply we want to 'tag' an object with some value. For example, the GendL cylinder wifeframe object doesn't support a message volume, but say we have a number of objects that do, and a cylinder, and we want to process the volumes using mapcar.

(define-object pseudo-inputs (base-object):computed-slots((volumes (mapcar #'(lambda(a) (theo a volume)) (the children)))):objects((my-box :type 'box:length 2:width 3:height 4:sequence (:size 3))(my-cylinder :type 'cylinder:radius 2:height 6:pseudo-inputs (:volume):volume (div (* (the-child height)(expt (the-child radius) 2)pi) 2))))
In this code, we have an input volume defined for cylinder, but cylinder doesb't have a corresponding :input-slot, so we have identified this input as a :pseudo-input. Note that, if we don't definevolume as a pseudo-input, the code will still work but we will get a compiler warning. Whilst this is the case, its good practice from a coding perspective to identify such slots correctly

GDL-USER> (make-self 'pseudo-inputs)

#<PSEUDO-INPUTS #x210485A1BD>

GDL-USER> (the volumes)

(37.69911184307752 24 24 24)