Saturday, July 6, 2013

Introspecting the Lisp Representation of a Maxima Variable

I recently wanted to know how Maxima (a computer algebra system) implemented something.  I searched and searched and couldn't solve my problem.  Specifically, I wanted to access a Maxima structure from within Lisp code.  However, I didn't know how the structure was implemented in Lisp and therefore didn't know how to access it.

All you need is a single line of inline Lisp:



structures is a global variable which stores the structures that have been defined in the session by using defstruct().  I wasted a few hours looking for this information to come up with 25 characters that would answer my question.  Applying the same general idea to an instance of PanelStruct() tells me how it is implemented.  By the way, the answer to my questions looks like this:

((MLIST)
  ((|$PanelStruct|) $SIZE $TOP $CENTER $BOTTOM $ZENITH $AZIMUTH |$rdv|)
  ((|$RayStruct|) $START $DIRECTION) 

  ((|$PlaneStruct|) $NORMAL $CONSTANT)      
  ((|$PanelStruct|) $SIZE $TOP $CENTER $BOTTOM $ZENITH $AZIMUTH |$rdv|)   
  ((|$RayStruct|) $START $DIRECTION) 
  ((|$PlaneStruct|) $NORMAL $CONSTANT)) 
((MLIST) 
  (($PanelStruct) $SIZE $TOP $CENTER $BOTTOM $ZENITH $AZIMUTH $rdv) 
  (($RayStruct) $START $DIRECTION) 
  (($PlaneStruct) $NORMAL $CONSTANT)
  (($PanelStruct) $SIZE $TOP $CENTER $BOTTOM $ZENITH $AZIMUTH $rdv) 
  (($RayStruct) $START $DIRECTION) 
  (($PlaneStruct) $NORMAL $CONSTANT))

The near repeat is caused by the print function returning what it has printed and Maxima outputting it.  The $ indicates a references to a Maxima variable and the | | symbols indicate a case sensitive reference.  Oddly, the case is reversed for RDV (which is documented) but not for PanelStruct which surprises me.  (These structures are not built-in but were user-defined in my Maxima session.)

I will still need to figure out how I'm going to use the information, but I have a working concept.
Post a Comment