Skip to main content

$Increment and $Sequence Functions

In order to put everything you've learned about arrays and globals together, in the next exercise you're going to add a method to your data entry class to store the data that the user enters. You just need to learn about one more simple function: $Increment. It's very simple; it takes a variable and an optional increment and increments the variable, and also returns the new value. The increment can be a positive or negative number. You'll use it in its simplest way, with a default increment of 1.

Although you can use $Increment with a variable, its primary purpose is for quickly and atomically incrementing a global node in order to generate a unique ID number. You'll use it in this way in the next exercise.


USER>write a

USER>write $increment(a)
USER>write $increment(a)
USER>write $increment(a, 2)
USER>write a

If 20 people were using the simple data entry application to add records to the database at the same time, $Increment would have no trouble keeping up. But if the intake speed was much greater (for example, 100 processes receiving 10,000 records per minute electronically), $Increment would start to become a bottleneck. For cases like this, ObjectScript provides $Sequence, which does not take an increment argument. Here's what it does when you use it to increment a global node:

  • On a system that isn't very busy, $Sequence increments the global node by 1, just like $Increment.

  • On a busy system, $Sequence increments the node by a larger number, and assigns each process a range of unique ID numbers instead of just one. The next time a process uses $Sequence, it simply returns the next ID number in its range. When the range is exhausted, the next call to $Sequence will increment the global node again and assign a new range to the process. If the system gets busier, $Sequence assigns larger ranges; if the system quiets down, the ranges get smaller again.

FeedbackOpens in a new tab