body { margin:0px; background-color:#fff } img { margin:0px; border-style:none } button { margin:0px; border-style:none; padding:0px; background-color:transparent; vertical-align:top } p:first-child { margin-top:0px } table { empty-cells:hide } .f-sp { font-size:1px; visibility:hidden } .f-lp { margin-bottom:0px } .f-x1 { } .f-x2 { } .f-x3 { } a:visited { color:#8b0000; text-decoration:underline } .capsub { color:#808080; font-weight:bold; text-transform:uppercase; letter-spacing:2.4px } .style31 { color:#000 } .code { color:#000; font-family:monospace } .style9 { margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0.1px } .style56 { color:#000; margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0.1px } .rightaligned { margin-left:0px; margin-right:0px; text-align:right; margin-top:0px; margin-bottom:0.1px } .style38 { color:#000; font-style:italic } .style21 { margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .small { color:#000; font-size:90% } .style42 { color:#000; font-weight:bold; font-size:90% } .style33 { color:#808080; font-style:italic; font-size:90% } .style54 { color:#808080; font-style:italic; font-size:90%; margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .footer { color:#808080; font-size:90% } .FWExtra { } .FWExtra a:link { text-decoration: none; } .FWExtra a:active { text-decoration: none; } .FWExtra a:visited { text-decoration: none; } .FWExtra a:hover { text-decoration: underline; } -->
Equi4 Softwareitem2

Jump to part:
1 - 2 - 3 - 4 - 5
API

an introduction to ratcl - Part 5

Ratcl assumes ownership of the data it manages. You define structures, and then fill them by copying data to Ratcl. Likewise, when accessing data, you will get back a copy. All memory is automatically managed by Ratcl (it has its own garbage collection).

One reason for this approach is that Ratcl applies operators to potentially large datasets. By putting Ratcl in charge, it can do so without having to call back into the host environment and without constant data conversions.

This means Ratcl is best suited as data repository - it does a lot of things behind the scenes, which will be less effective if you manage data yourself. Having said that, Ratcl can manipulate a list or array for you - you can always copy the data into Ratcl, apply the operations, and take it back out. It'll merely add some overhead.

 % array set APart of the design effort going into Ratcl is to make both approaches convenient in Tcl.

The example shown on the right illustrates how to copy data from a Tcl array into a view:

Note that Tcl arrays don't maintain order, so as you can see, rows may get re-shuffled in the transition.

 % array set CGetting elements out is just as simple:

This time parray makes the order come out as expected, since it always sorts on key.

 some examples

To sort an array based on its values, treating those values as integers:

 % array set a

To "invert" the above array, i.e. to switch the role of its keys and values:

 % array set b

Note that Tcl 8.5 will introduce dictionaries, which act like arrays-by-value. These should fit in nicely, since their representation is the same pairwise list as used by "array set" and "array get".

slice and project

 % [[T mapcol {AWhen extracting data from a view, it is more efficient to only extract as much as needed.

If you only need columns A and B, rows 2 through 4, then instead of extracting everything and skipping over some data in Tcl, use the slice and mapcol operators before transferring data, as shown here.

This leads to less data crossing the Tcl <-> Ratcl boundary, which means it will be faster and consume less memory.

As a general rule, it is better to shape the data in Ratcl before extraction. For example, if you are displaying a view in a GUI list style, the best way to do so is to only extract the slice which is actually visible.

Conversely, it's best to extract as much as possible at once. Instead of iterating in Tcl and issueing Ratcl commands to extract individual rows, it's better to figure out what the rows are (perhaps using "maprow" to select/order them) and then extract the result in one call. This causes less traffic across the Tcl <-> Ratcl boundary.

summary

This concludes the introduction to Ratcl. Not all the details have been covered, and many operators have been left out for brevity, but you should now have an idea of what sort of data manipulations Ratcl offers and how it all looks and feels in Tcl.

Keep in mind that Ratcl is new, and some of it is still evolving further.

The final page lists the Ratcl API, i.e. all calls and operations it supports.

Ratcl API...