Hi Mira: Below is a note by Salil Pradhan from Nov. 6 1995. Visitors should be improved to better deal with object modifications. The current solution can be made more structure-shy. from X to J ... Visitor{ ... replace J (@ exp @) } Replaces J-object by expression exp. Without this feature, we would have to stop at the predecessor of J, encoding more structure into the program than needed. -- Karl ============= //test cd for *replace* X = N. N = J. J = JA | JB | JC. JA = "JA". JB = "JB". JC : JD | JE. JD = "JD". JE = "JE". ------------------------------------------------------- //Doesn't like JA, changes all JAs to JBs. *operation* void metam() *traverse* *from* X *to* J *replace* J {*typecheck*} //*typecheck* is optional *prefix/suffix* // just before entering or after exiting object form // of J *ifholds* (@ demold->get_type() == "JA" @) // could have just as well traversed to JA rendering the ifholds // clause superflous. But I wanted to demonstrate use of IFHOLDS *new* (@ new JB() @) //new object J or subclass *old* (@ delete demold; @) // *old* is what to do with the old value. 'demold' is the actual old // value and is of the type Universal *. Value is always saved in 'demold' // In the example above .. demold = j .. Use of a std variable will // make the replace macro more adaptive .. -------------------------------------------------------------------------- --Explanation Wrapper for replacement is attached as a prefix/suffix wrapper to XXX, xxx, J . Where XXX is the class containing link xxx to an object of the class J (in this example). j can only be replaced by JA,JB, or the concrete sub-classes of JC. The TYPECHECK option ensures that the type if the replacee is compatable with the pointer it is being assigned to. This may be used during program development and later removed to improve run-time efficency. With Typecheck ON Make a list of construction classes that may replace the class in question. The *new* construct returns an object, check if the type of the object (get_type()) is in the list. If it is then replace this as the new object and save the old in the variable demold.