Saturday, December 17, 2011

Adding Subcharts to RAPTOR Programs

What is a subchart in RAPTOR?
A subchart is just a separate set of RAPTOR symbols in a program. A subchart has a start symbol and an end symbol just like the "main" program. A subchart can be made to run with a Call symbol from main or from another subchart. Subcharts are used to modularize RAPTOR programs. A long or complex RAPTOR program can be organized into several subcharts. It's a "divide and conquer" approach to programming. Subcharts provide another benefit, too. They can be called over and over again as many times as needed.
How do you make subcharts?
To add a subchart to main, right click on the main tab and select "Add subchart" from the popup menu.
Here we are adding a subchart named verse1 to main. This will create a new tab named verse1 so we can access the subchart to add symbols. We are writing a RAPTOR program to print the lyrics to the song "Louie, Louie". This song follows the "verse-chorus" pattern. We can display the entire song by creating and calling subcharts for the verses and chorus. The chorus is always the same so we have to write it only once and call it where needed. The lyrics to the verse1 subchart are shown on the left below. Note that the verse1 tab is selected.
How do you run a subchart?
Subcharts only run when called. To call a subchart, add a RAPTOR Call symbol to main and configure it with the subchart's name as shown on the right above. Next, we add another subchart for the chorus wih outputs to display the chorus lyrics. Then we add another Call symbol to main and configure it to run the chorus subchart. Both steps are shown below. Note we now have three tabs.
Finishing Louie, Louie
To complete the lyrics program we write and add subcharts for the remaining verses, but we don't have to write another chorus. We can reuse the chorus subchart where needed. The completed Louie, Louie main program appears below. Note that we have five tabs but only one for the chorus. I added the guitar solo, too. Note that subcharts nicely organize the program into a simple modular style. All programming languages have similar features for making programs modular.

Oops. I don't have any comments in my program. My bad. Add comments to all of your programs!