3
$\begingroup$

This question already has an answer here:

I guess I am used to using data structures in most languages, the closest function for Mathematica would be similar to the defstruct macro in Lisp... is there such a thing?

$\endgroup$

marked as duplicate by WReach, MarcoB, m_goldberg, happy fish, gwr Mar 22 '17 at 6:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ What does defstruct do? $\endgroup$ – Michael E2 Mar 21 '17 at 16:54
  • $\begingroup$ It creates a set of function to access list elements, say you have a structure named aStruct with elements {arg1, arg2, arg3). defstruct defines functions that access these elements directly $\endgroup$ – guymadison Mar 21 '17 at 17:14
  • 1
    $\begingroup$ The macro function defineAccessors from (13722) is like a lightweight version of defstruct. $\endgroup$ – WReach Mar 21 '17 at 19:43
  • 1
    $\begingroup$ @guymadison For the need you describe, what is the gain over an Association, which effectively comes with accessors? (Type checking could be handled by a constructor, if that's the issue.) $\endgroup$ – Alan Mar 22 '17 at 2:41