Often I like to define my own functions that are almost exactly the same as Mathematica defined functions, apart from a few tweaks. See this question for example. I want to define them properly so they handle optional arguments correctly. What is a general strategy for accomplishing this? Here's a concrete (esoteric) example. I define myListPlot
that is almost identical to ListPlot
except that is adds a gridline corresponding to the first data point.
data = Table[RandomReal[], {x, 1, 10}]
myListPlot[data_, opts_] := ListPlot[data, GridLines -> {None, {data[[1]]}}, opts]
myListPlot[data, {PlotStyle -> Red, Joined -> True}]
Not too bad. However I have to pass the optional arguments as a list. Instead, I would like to pass the optional arguments in the same way one does with ListPlot
. In other words, I would like to modify myListPlot
so that I would pass arguments like
myListPlot[data, PlotStyle -> Red, Joined -> True]
Perhaps I'm going about this completely the wrong way. Nevertheless I hope the reader understands what I'm trying to accomplish and can suggest a solution.
myListPlot[data_, opts_]
tomyListPlot[data_, opts___]
. $\endgroup$