Discussion:
What's the difference between a ::ROUTINE and a procedure?
(too old to reply)
Robert Bridges
2020-05-31 20:06:12 UTC
Permalink
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
2020-05-31 21:30:23 UTC
Permalink
Post by Robert Bridges
"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.)
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
2020-05-31 21:36:57 UTC
Permalink
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

Loading...