Sorry for being unprecise. I'm just wondering if your solution is the "official" way to deal with optional list arguments like in ImageTake
. I also tried f[args:{x_, y_}:{1,2}] := {x, y}
which seems to work. However, I'm not sure if understand it the right way...
I do not believe I have seen a guideline or even a standard practice for this particular case. I quite like Kuba's solution and I often make use of that method, e.g.: Can I make a default for an optional argument the value of another argument?
You chose ImageTake
as a model. For this function there is no need for the optional behavior that you describe as the syntax is already handled by Take
. Note:

This syntax is valid for each argument of ImageTake
(after the first) just as it is for Take
. Therefore a trivial reimplementation is:
myImageTake[i : _Image | _Image3D, spec__] :=
Head[i][Take[ImageData[i], spec], ColorSpace -> ImageColorSpace[i]]
Test:
img = Import["http://cdn.sstatic.net/mathematica/img/[email protected]"] (* site logo *)
myImageTake[img, -66, {30, 120}]
ImageTake[img, -66, {30, 120}]

img3D = ExampleData[{"TestImage3D", "CThead"}];
myImageTake[img3D, -20, {80, 180}, 120]
ImageTake[img3D, -20, {80, 180}, 120]

If I wanted tighter control of the input than spec__
I would use something like:
p1 = (All | _Integer | {Repeated[_Integer, {1, 3}]})?(FreeQ[#, 0] &);
ClearAll[myImageTake]
myImageTake[i : _Image | _Image3D, spec : p1 ..] /;
Length[{spec}] <= Length@ImageDimensions[i] :=
Head[i][Take[ImageData[i], spec], ColorSpace -> ImageColorSpace[i]]
This example may be a bit too specific but it is the one that you gave. For other examples the pattern you found (args:{x_, y_}:{1,2}
) or the method of passing arguments back to the function (Kuba's answer and my linked post above) may be more appropriate. If you give another example or model function I shall try to address that as well.
f[] = f[{}]
later, it this ok? $\endgroup$ImageTake
which use optinal and default arguments in list form. Basically I want to implement the same functionality regarding optional arguments as inImageTake
, see the documentation. $\endgroup$ImageTake
. I also triedf[args:{x_, y_}:{1,2}] := {x, y}
which seems to work. However, I'm not sure if understand it the right way... $\endgroup$Needs["GeneralUtilities`"];
and evaluatePrintDefinitions@Cells
, as you can see, WRI is not trying to put everything in one pattern either. It is not handy nor readable. $\endgroup$