REBOL for COBOL programmers

Go to table of contents Go to feedback page


Date written: May 2, 2013
Date revised:
Date reviewed:

This page explains some REBOL equivalents of INSPECT.


The INSPECT statement has a number of variations, but the main use of it is counting characters in a data item and doing the "find and replace" operation on a data item. For example,

INSPECT identifier-1 REPLACING ALL { identifier-2 } BY { identifier-3 }
                                   { literal-1    }    { literal-2    }
The above, as you know, is just an example. There are options for counting characters in a data item, and more complicated replacing. Another common operation is replacing leading spaces by zeros, as one might do when fixing up user input.

The REBOL equivalent

REBOL has the "replace" function to replace parts of data items. It can be applied to a string, as one would do in COBOL, but it also can be applied to any of the "series" data types, like a block. As for an operation like counting leading blanks or zeros, dealing with fixed-format data is not so much in the scope of things that REBOL does. Data in REBOL is more free-format, so operations like that are not as easily supported as in COBOL. The description of the REBOL "replace" to match the above COBOL example would be something like:

replace/all identifier-1 { identifier-2 } { identifier-3 }
                         { literal-1    } { literal-2    } 
The "all" refinement replaces all. Without it, only the first item would be replaced.