body { margin:0px; background-color:#fff } a:visited { color:#8b0000; text-decoration:underline } .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...