Search code examples
rascal

Making Rascal structures looking better


To keep structures clear is it possible to name them. So essentially I asking for a 'struct' in Rascal. So eg:

list[tupple[map[str,int],int]]

to:

treeLabel :: str
occurences :: int
treeData :: map[treeLabel,int]
treeNode :: tupple[treeData,int]
tree :: list[treeNode]
tree x=[];

Tx

Jos


Solution

  • How about using Abstract Data Types?

    See Rascal Tutor. The above could then look like this:

    data MyStruct = ms(str treeLabel, 
                       int occurrence, 
                       map[treeLabel, int] treeData,
                       tuple[TreeData td, int n] treeNode,
                       list[TreeNode] tree);
    

    given some variable m with a myStruct value you can access elements with the usual dot notation:

    m.treeLabel;
    m.treeLabel = "xyz";
    

    etc.