1

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?

hmode
  • 482
  • 3
  • 8

1 Answers1

0

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}]]

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • SequenceForm is listed as an obsolete symbol now, but the replacements, Row and Text didn't seem to work the same way. – hmode Dec 21 '18 at 21:00