Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Was internal routine called as Subroutine or Function? 1

Status
Not open for further replies.

Swiftie

Programmer
Jan 14, 2017
2
0
0
GB
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'

Steve Swift
 
The routine in ooRexx can be called as a subroutine (using CALL) or as a 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:
[COLOR=#a52a2a][b]call [/b][/color][COLOR=#008b8b]silent[/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#6a5acd]result[/color]

[COLOR=#a52a2a][b]call [/b][/color][COLOR=#008b8b]silent[/color] 1[COLOR=#a52a2a][b],[/b][/color] 2
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#6a5acd]result[/color]

[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#008b8b]silent([/color]3[COLOR=#a52a2a][b],[/b][/color] 4[COLOR=#008b8b])[/color]

[COLOR=#a52a2a][b]exit[/b][/color]

[COLOR=#008b8b]silent[/color][COLOR=#a52a2a][b]:[/b][/color] [COLOR=#a52a2a][b]procedure[/b][/color]
  [COLOR=#a52a2a][b]parse arg[/b][/color] my_arg
  [COLOR=#a52a2a][b]if[/b][/color] my_arg [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]""[/color] [COLOR=#a52a2a][b]then[/b][/color]
     rslt [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]"nothing passed"[/color]
  [COLOR=#a52a2a][b]else[/b][/color]
     rslt [COLOR=#a52a2a][b]=[/b][/color] [COLOR=#ff00ff]"argument passed:"[/color] my_arg
  [COLOR=#0000ff]--[/color]
  [COLOR=#a52a2a][b]return[/b][/color] rslt

Result:
Code:
$ rexx foo_example.rex 
nothing passed
argument passed: 1
argument passed: 3
 
Perhaps I should have asked:
Can the routine "Silent" determine whether it has been called as a Subroutine or called as a Function?
See
A version which can tell the difference:

Call Silent
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
 
You answered your question self.
I didn't know it before and learned something new :)

But, it seems that
Code:
parse source operatingSystem [COLOR=#204A87]commandType[/color] sourceFileName

contains in commandType FUNCTION or SUBROUTINE only when we use ooREXX specific declaration
Code:
::routine silent

When we use the standard REXX declaration
Code:
silent: procedure
then commandType contains in all cases COMMAND
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top