INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Was internal routine called as Subroutine or Function?

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'

Steve Swift http://www.swiftys.org.uk

RE: Was internal routine called as Subroutine or Function?

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

call silent
say result

call silent 1, 2
say result

say silent(3, 4)

exit

silent: procedure
  parse arg my_arg
  if my_arg = "" then
     rslt = "nothing passed"
  else
     rslt = "argument passed:" my_arg
  --
  return rslt 

Result:

CODE

$ rexx foo_example.rex 
nothing passed
argument passed: 1
argument passed: 3 

RE: Was internal routine called as Subroutine or Function?

(OP)
Perhaps I should have asked:
Can the routine "Silent" determine whether it has been called as a Subroutine or called as a Function?
See http://www.swiftys.org.uk/wiz?568

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 http://www.swiftys.org.uk

RE: Was internal routine called as Subroutine or Function?

You answered your question self.
I didn't know it before and learned something new smile

But, it seems that

CODE

parse source operatingSystem commandType 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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close