Suppose that I have a function that has two patterns:
disksConstantRadius[radius_][points_] := Disk[#, radius] & /@ points
(noting that this would be better---but less readable---as)
disksConstantRadii[radius_?NumericQ][points_ /; ArrayQ[points, 2,NumericQ]] :=
Disk[#, radius] & /@ points
The above works just fine.
The objective is to make an operator form of Disk that operates on a list of points, but the question is more general.
Is there a name for this construction f[][]??
This is just idle curiosity (I clearly have a work-around), but would it be possible to make the function be Listable in its second argument?
I'm not surprised that this
Clear[disksConstantRadius];
Attributes[disksConstantRadius] = {Listable}
disksConstantRadius[radius_?NumericQ][{x_, y_}] :=
Disk[{x, y}, radius]
doesn't work.
And also not surprised that this:
Clear[disksConstantRadius];
Attributes[disksConstantRadius[_]] = {Listable}
disksConstantRadius[radius_?NumericQ][{x_, y_}] :=
Disk[{x, y}, radius]
doesn't work either.
How could one construct an operator form disksConstantRadius[radius]
?
There is a nice discussion about Listable here: The role and meaning of Listable, Leonid Shifrin, 2013
diskConstantRadii[r_] :=diskConstantRadii[r]= Compile[{{p,_Real,1}}, Evaluate[Disk[{Indexed[p,1].Indexed[p,1]},r],Attributes->Listable]
. I’m just curious how one might do the f[][] version programmaticaly. My goal is to learn a new tick. $\endgroup$f
listable if the basic call has the formf[{x_, y_}]
. Iff
is listable, thenf[{x, y}]
becomes{f[x], f[y]}
before any definitions forf
are applied. It doesn't matter whetherf
is a symbol or a head likedisksConstantRadius[r]
. It can't be done viaListable
. The restriction on subvalues is a red herring, and you have to useMap
orThread
. $\endgroup$