In Mathematica there are different objects like InterpolatingFunction or SparseArray? How can I define a custom data object with special data structure?
Example:
f = Interpolation[{1, 2, 3, 5, 8, 5}];
f // InputForm
returns us
InterpolatingFunction[{{1, 6}}, {4, 3, 0, {6}, {4}, 0, 0, 0, 0, Automatic},
{{1, 2, 3, 4, 5, 6}}, {{1}, {2}, {3}, {5}, {8}, {5}}, {Automatic}]
But if one evaluates the above output one gets back
InterpolatingFunction[{{1, 6}}, <>]
I could not find any documentation how to do it for any custom data object that I want to define for my program.
Answer
Format is what you are looking for: Create a data structure, something like this:
mkMyData[d1_, d2_] := MyData[d1, d2]
GetD1[a_MyData] := a[[1]]
GetD2[a_MyData] := a[[2]]
Format[MyData[d1_, d2_]] := "MyData[<" <> ToString[Length[d1] + Length[d2]] <> ">]"
Call the constructor:
data = mkMyData[Range[5], q]
(* "MyData[<5>]" *)
Call a selector:
GetD1[data]
(* {1, 2, 3, 4, 5} *)
Comments
Post a Comment