Edit:
I think in my original post, I missed emphasizing the main point. This is mainly a pattern matching question. If you're interested in the 'why' of this question, please read the original post below. The short question:
Suppose I have a newly defined, unevaluated Head, called NewHead. I define a function associated with NewHead as (I add in the x & y to emphasize that the argument list can be arbitrary so long as it contains n_NewHead)
In[1]= NewHead /: func[x_, n_NewHead, y_] := n This has
In[2]= UpValues[NewHead] Out[2]= {HoldPattern[func[x_, n_NewHead, y_]] :> n} I would like to use pattern matching so I can transform this UpValue list like
In[3]= UpValues[NewHead] /. (* Some pattern matching here resulting in: *) Out[3]= {HoldPattern[func[x_, d_DerivedHead, y_]] :> func[x, d[[1]], y]} The point is to make a 'class' DerivedHead that inherits all the functions of the 'class' NewHead. A NewHead object would be stored in Part 1 of a DerivedHead object. For an example, read the original post below.
The thing I can't figure out is how to pattern match on n_NewHead (in Out[2]) . The name of the pattern _NewHead can, in principle, be anything, and the argument list to func is similarly arbitrary.
Any advice is appreciated!
- Seth
Original post below:
I have read some posts here on object oriented programming as well as many pattern matching posts, but nothing (I have found) seems to address this case, so I thought I'd ask a question.