Varkon documentation index

VARKON - Documentation

# The REF datatype

Each entity in VARKON has a unique identity composed by sequence number and order number. The following line for example...

      lin_free(#5,p1,p2);

has a sequence number equal to 5. If the line statement is placed in a for-loop and executed more than once....

      for i:=1 to 10 do
        lin_free(#5,p1,p2);
      endfor;

then the first line becomes #5.1 the second #5.2 and so on. Ordernumbers are created automatically by Varkon at runtime. In order to refer to an entity belonging to a specific part we must also know the identity of the part. If a module A calls a module B using part(#1,B()) and module B creates a line #5 then the global identity of the line is #1#5. Replace the #'s with slashes and think of how your files are organized in a tree structure on your harddisk. This is almost the same. Varkon includes a special datatype called REF used to hold the value of an identity....

      REF id;

      id:=#5.2#7#8#2.25;

In this example a variable of type REF is declared and assigned a value representing a reference to an entity #2.25 in a part #8 belonging to a part #7 belonging to the second instance of the part #5.

References just like filepaths are normally treated as local meaning they are relative to the position in the tree where they are used. A global reference though is treated as relative to the absolute top of the tree structure. The syntax in MBS is ## for a global and # for a local reference.

      id:=##5.2#7#8#2.25;

This is the global version of the previous example. A REF-parameter is a powerful way to express a relation between two objects. The following module creates a point in the middle of an arbitrary line.

      MODULE mid_point(REF line_id;);

      BEGINMODULE
        poi_free(#1,on(line_id,0.5));
      ENDMODULE

Varkon version 1.19C svn# 120