1
$\begingroup$

I have a function that operates on EventData and has a return value that has Properties (or things that act like Properties). I'd like to clean up the return InputForm when queried, but I'm not quite sure how to go about it.

myfunc[x_] := Module[{returnvalue},
  returnvalue["Data"] = x;
  returnvalue["Mean"] = Mean[x];
  Format[returnvalue, StandardForm] := HoldForm["myfunc"][x];
  Format[returnvalue, InputForm] := HoldForm["myfunc"][x];
  Return[returnvalue]
]

My data is just EventData:

e = {1, 2, 3, 4, 5, 6};
ci = {0, 1, 0, 0, 0, 1};
dat = EventData[e, ci];

a = myfunc[dat]

When I run InputForm[a], I get the following:

HoldForm["myfunc"][EventData[Automatic, {{1, 2, 3, 4, 5, 6}, {0, 1, 0, 0, 0, 1}, None}]]

What I'd like to get is:

myfunc[EventData[Automatic, {{1, 2, 3, 4, 5, 6}, {0, 1, 0, 0, 0, 1}, None}]]

How should I define the Format command in the body of myfunc to get the output that I'm looking for?

$\endgroup$
0
$\begingroup$

Just use SequenceForm instead of HoldForm (and don't use Return):

myfunc[x_] := Module[{returnvalue},
    returnvalue["Data"] = x;
    returnvalue["Mean"] = Mean[x];
    Format[returnvalue, StandardForm] := HoldForm["myfunc"][x];
    Format[returnvalue, InputForm] := SequenceForm[myfunc][x];
    returnvalue
]

Your example:

e = {1,2,3,4,5,6};
ci = {0,1,0,0,0,1};
dat = EventData[e,ci];

a = myfunc[dat];
a //InputForm

myfunc[EventData[Automatic, {{1, 2, 3, 4, 5, 6}, {0, 1, 0, 0, 0, 1}, None}]]

$\endgroup$
  • $\begingroup$ SequenceForm is listed as an obsolete symbol now, but the replacements, Row and Text didn't seem to work the same way. $\endgroup$ – hmode Dec 21 '18 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.