I really miss having something like a struct
in Mathematica. I know of (and regularly use) a couple of programming techniques which feel like a struct
(e.g., using downvalues), but are ultimately unsatisfactory (perhaps I'm using downvalues incorrectly). What programming approaches are available which provide similar functionality to a struct
?
Here's an abbreviated (and hopefully not too obtuse) example of how I use downvalues to emulate a struct. In this case, I'm distinguishing between TLC and TEC (these are sets of parameters for two different phases of a Moon mission, trans-lunar cruise and trans-earth cruise):
deadBandWidth[X][TLC] ^= 10. \[Degree];°;
deadBandWidth[Y][TLC] ^= 10. \[Degree];°;
deadBandWidth[Z][TLC] ^= 20. \[Degree];°;
sunSearchAngle[Z][TLC] ^= 230. \[Degree];°;
sunSearchRate[Z][TLC] ^= 1. \[Degree]°/Second;
sunSearchAngle[X][TLC] ^= 75. \[Degree];°;
sunSearchRate[X][TLC] ^= 1. \[Degree]°/Second;
safingSpinRate[TLC] ^= (360. \[Degree]°)/Day;
sunVector[TLC] ^= {-Cos[45. \[Degree]]°], 0., Sin[45. \[Degree]]°]};
safingSpinAxis[TLC] ^= sunVector[TLC];
deadBandWidth[X][TEC] ^= 20. \[Degree];°;
deadBandWidth[Y][TEC] ^= 20. \[Degree];°;
deadBandWidth[Z][TEC] ^= 20. \[Degree];°;
sunSearchAngle[Z][TEC] ^= 230. \[Degree];°;
sunSearchRate[Z][TEC] ^= 1. \[Degree]°/Second;
sunSearchAngle[X][TEC] ^= 75. \[Degree];°;
sunSearchRate[X][TEC] ^= 1. \[Degree]°/Second;
safingSpinRate[TEC] ^= (360. \[Degree]°)/Hour;
sunVector[TEC] ^= {0., 0., +1.};
safingSpinAxis[TEC] ^= sunVector[TEC];
?TLC
Global`TLC
safingSpinAxis[TLC]^={-0.707107,0.,0.707107}
safingSpinRate[TLC]^=6.28319/Day
sunVector[TLC]^={-0.707107,0.,0.707107}
deadBandWidth[X][TLC]^=0.174533
deadBandWidth[Y][TLC]^=0.174533
deadBandWidth[Z][TLC]^=0.349066
sunSearchAngle[X][TLC]^=1.309
sunSearchAngle[Z][TLC]^=4.01426
sunSearchRate[X][TLC]^=0.0174533/Second
sunSearchRate[Z][TLC]^=0.0174533/Second