Was internal routine called as Subroutine or Function?
Was internal routine called as Subroutine or Function?
(OP)
Hello. I'm new around here.
Whilst I worked as a programmer (mainly in REXX) in IBM for 37 years, I'm now retired, but I hope that I'll qualify. I'll probably ask a few questions, and try to help most of the time.
I came here to ask a question, so here it is:
In the following snippet of code, using Open Object REXX, can the routine "Silent" determine if it has been called as a Subroutine or as a Function?
...
Call Silent
Say Silent(1)
...
Silent: Procedure
-- Was I called as a Subroutine or as a Function
...
Return 'Maybe'
Whilst I worked as a programmer (mainly in REXX) in IBM for 37 years, I'm now retired, but I hope that I'll qualify. I'll probably ask a few questions, and try to help most of the time.
I came here to ask a question, so here it is:
In the following snippet of code, using Open Object REXX, can the routine "Silent" determine if it has been called as a Subroutine or as a Function?
...
Call Silent
Say Silent(1)
...
Silent: Procedure
-- Was I called as a Subroutine or as a Function
...
Return 'Maybe'
Steve Swift http://www.swiftys.org.uk
RE: Was internal routine called as Subroutine or Function?
In both cases the eventually arguments must be separated with commas, but when called as function they must be enclosed in (...) too.
When it is called as a subroutine (using CALL) then the eventually returned result is available in the special variable RESULT.
For example I tried this:
CODE
Result:
CODE
RE: Was internal routine called as Subroutine or Function?
A version which can tell the difference:
Say 'Silent was called as a' silent()
Exit
::Routine Silent
Parse source . how .
If How = 'SUBROUTINE' then say 'Silent was called as a' how
Return how
But, I frequently want to refer to variables from the calling routine, so ::REQUIRES is not always appropriate. Using Classic REXX, inside IBM, we had a CALLER MODULE which could be used to interrogate variables and environment in the calling code. But I don't recall that being able to determine HOW the called routine had been called. And I've never found an equivalent for OORexx
Steve Swift http://www.swiftys.org.uk
RE: Was internal routine called as Subroutine or Function?
I didn't know it before and learned something new
But, it seems that
CODE
parse source operatingSystem commandType sourceFileName
contains in commandType FUNCTION or SUBROUTINE only when we use ooREXX specific declaration
CODE
When we use the standard REXX declaration
CODE