To explain better what I mean I'll give an example of what I want the symbol to do. I want a symbol that wraps around a unit vector to use it as head for further calculations.
Something like:
UnitVector[{1,0,0}]
UnitVector[{1,1,0}]
(* UnitVector[{1,0,0}] *)
(* $Fail *)
so after I can use it in a function like:
RandomStuff[arg_UnitVector]:=(* Some procedure that requires the argument to be a unit vector *)
I know this can be easily done with a wrapper function that just returns a UnitVector
, but I would also like to know how to do this and if it is considered a good or bad practice.
unitVectorQ[v_?VectorQ] := TrueQ@Simplify[Norm[v] == 1]; unitVectorQ[_] := False; f[arg_?unitVectorQ] := (*etc*)
. I can't call to mind a use-case in which having a wrapper head on a standard sort of object like a vector would be convenient. I imagine my code would have to check, add, and remove the wrapper all the time. (Compare for example all the complaints on this site gets aboutMatrixForm
.) $\endgroup$SparseArray
but with a different coodinate system and an standard vector. The first one is easier to write as user and the second one is easier to operate, that is why I want a head wraper. $\endgroup$