What's the difference between a ::ROUTINE and a procedure?

35 views
Skip to first unread message

Robert Bridges

unread,
May 31, 2020, 4:06:13 PM5/31/20
to
So I wrote my first working ooRexx program (thanks offered to those who helped me over the first hump). Now I'm reading the programmer's guide in a more leisurely fashion, and I've paused to contemplate the ::ROUTINE directive:

"You use the ::ROUTINE directive to create a named routine within a program. The ::ROUTINE directive starts the named routine and another directive (or the end of the program) ends the routine.

"The ::ROUTINE directive is useful organizing functions that are not specific to a particular class type."

Sounds like a procedure to me. What's the difference?

/* Code example */
call routine
exit 0

routine: procedure
say 'Hi, there!'

::ROUTINE routine
say 'Hi, there!'
/* code ends */

In this simplest form, is there any practical difference? (I do see from the definition in the Reference that ::ROUTINE can do other things as well, though I'm still absorbing exactly what those are.)

Rick McGuire

unread,
May 31, 2020, 5:30:24 PM5/31/20
to
A ::ROUTINE is invoked like an external call, so it gets a new variable set, does not inherit things like digits settings or signal traps. It also cannot see labels in the main program. Using PROCEDURE on an internal call just creates the new variable set, the other settings get inherited from the caller.

One big advantage of using ::ROUTINE is that you can group a large number of functions in a single file and call them from other programs by using ::REQUIRES to access them.

Rick


Rick McGuire

unread,
May 31, 2020, 5:36:57 PM5/31/20
to
One other important difference with ::ROUTINE is scope. A procedure, since it depends on labels, is only visible within the code unit that declares the label. A ::ROUTINE can be accessed by any other code unit (such as within a ::METHOD).

Rick
Reply all
Reply to author
Forward
0 new messages