how do you invoke a "Procedure"

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

how do you invoke a "Procedure"

GaryT
sorry to post such an elemental question but I'm not familiar with "procedure".  I need to call the following from my rexx program and get back the answer -- it's not the same as calling a subroutine like I know how to do:  It's supposed to turn the numeric "123" into "onehundredtwentythree" eg.

numwords: procedure

parse arg nn

 if nn<0 then return 'minus 'numwords(-nn)
 if nn=0 then return 'zero'
 ulist='one two three four five six seven eight nine ten '||,
  'eleven twelve thirteen fourteen fifteen sixteen '||,
  'seventeen eighteen nineteen'
tlist='shayla twenty thirty forty fifty sixty seventy '||,
'eighty ninety'
ranks='hundred thousand million billion trillion'
rankval='100 1000 1e6 1e9 1e12'
 if nn=trunc(nn) then do
    if nn<20 then return word(ulist,nn)
      if nn<100 then do
        if nn//10=0 then return word(tlist,nn%10)
        return word(tlist,nn%10)'-'word(ulist,nn//10)
      end
rankpos=words(rankval)
 do while nn<word(rankval,rankpos)
    rankpos=rankpos-1
 end
rv=word(rankval,rankpos)
wa=numwords(nn%rv)' 'word(ranks,rankpos)
 if nn//rv=0 then return wa
return wa' 'numwords(nn//rv)
 end
wa=numwords(trunc(nn))' point'
 do while (nn\=trunc(nn))
   nn=nn-trunc(nn)
   nn=nn*10
   wa=wa' 'numwords(trunc(nn))
 end
return wa
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

LesK
Administrator
Gary,

All PROCEDURE does is isolate the variable pool for the subroutine from the mainline code, unless EXPOSE
is coded. See the documentation for the Rexx interpreter that you're using.

So you can CALL it or use it as a function just like you normally would.

Les
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

GaryT
then why do I get error 17.1 Procedure" is valid only when it is the first instruction executed after an internal call or function invocation?
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

Rick McGuire
Because it IS only valid for an internal call or function.  I'm guessing you're trying to call this as an external file.  Just remove the label and the procedure, since they are not allowed in that sort of context.  An external call has an implied procedure anyway, so it isn't needed. 

Rick


On Thu, Nov 14, 2013 at 5:54 PM, GaryT [via Rexx Language Association Forum] <[hidden email]> wrote:
then why do I get error 17.1 Procedure" is valid only when it is the first instruction executed after an internal call or function invocation?


If you reply to this email, your message will be added to the discussion below:
http://rexx-language-association-forum.44760.x6.nabble.com/how-do-you-invoke-a-Procedure-tp1127p1130.html
To start a new topic under Classic Rexx, email [hidden email]
To unsubscribe from Rexx Language Association Forum, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

GaryT
making progress, the subroutine is doing exactly what I want, but I can't see why the variable "wa" is not being returned to the main program.  Also doesn't work if "input" ends in ".00"

/*rexx*/


input = 12345.67

call numwords input

say 'back in main program, wa is: ' wa

exit

numwords:procedure

parse arg nn

  if nn=0 then return 'zero'

ulist='one two three four five six seven eight nine ten '||,
  'eleven twelve thirteen fourteen fifteen sixteen '||,
  'seventeen eighteen nineteen'

tlist='nothing twenty thirty forty fifty sixty seventy '||,
'eighty ninety'

ranks='hundred thousand million billion trillion'

rankval='100 1000 1e6 1e9 1e12'
say 'nn now is'nn
 if nn=trunc(nn) then do
    if nn<20 then return word(ulist,nn)
      if nn<100 then do
        if nn//10=0 then return word(tlist,nn%10)
        return word(tlist,nn%10)'-'word(ulist,nn//10)
      end

    rankpos=words(rankval)
    do while nn<word(rankval,rankpos)
       rankpos=rankpos-1
    end

    rv=word(rankval,rankpos)
    wa=numwords(nn%rv)' 'word(ranks,rankpos)

    if nn//rv=0 then return wa
    return wa' 'numwords(nn//rv)
 end
wa=numwords(trunc(nn))' and'

   cents = nn-(trunc(nn))'/100 dollars'
   cents = cents~delstr(1,2)
   wa=wa' 'cents
say 'in subroutine wa is: 'wa

return wa
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

Rick McGuire
The procedure instruction you use at the start makes all variables local, so you're not going to see any changes.  The value you returned via the return instruction has been assigned to the variable RESULT, although given the way you are using this, you would be better off invoking this as a function:  

wa = numwords(input)


On Tue, Nov 19, 2013 at 2:51 PM, GaryT [via Rexx Language Association Forum] <[hidden email]> wrote:
making progress, the subroutine is doing exactly what I want, but I can't see why the variable "wa" is not being returned to the main program.  Also doesn't work if "input" ends in ".00"

/*rexx*/


input = 12345.67

call numwords input

say 'back in main program, wa is: ' wa

exit

numwords:procedure

parse arg nn

  if nn=0 then return 'zero'

ulist='one two three four five six seven eight nine ten '||,
  'eleven twelve thirteen fourteen fifteen sixteen '||,
  'seventeen eighteen nineteen'

tlist='nothing twenty thirty forty fifty sixty seventy '||,
'eighty ninety'

ranks='hundred thousand million billion trillion'

rankval='100 1000 1e6 1e9 1e12'
say 'nn now is'nn
 if nn=trunc(nn) then do
    if nn<20 then return word(ulist,nn)
      if nn<100 then do
        if nn//10=0 then return word(tlist,nn%10)
        return word(tlist,nn%10)'-'word(ulist,nn//10)
      end

    rankpos=words(rankval)
    do while nn<word(rankval,rankpos)
       rankpos=rankpos-1
    end

    rv=word(rankval,rankpos)
    wa=numwords(nn%rv)' 'word(ranks,rankpos)

    if nn//rv=0 then return wa
    return wa' 'numwords(nn//rv)
 end
wa=numwords(trunc(nn))' and'

   cents = nn-(trunc(nn))'/100 dollars'
   cents = cents~delstr(1,2)
   wa=wa' 'cents
say 'in subroutine wa is: 'wa

return wa



If you reply to this email, your message will be added to the discussion below:
http://rexx-language-association-forum.44760.x6.nabble.com/how-do-you-invoke-a-Procedure-tp1127p1140.html
To start a new topic under Classic Rexx, email [hidden email]
To unsubscribe from Rexx Language Association Forum, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

GaryT
ty

simple thing I didn't know.  I also don't know the syntax for function,  but this way will be fine when I figure out how to make it work for zero cents.
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

LesK
Administrator
It looks like its time for you to actually _learn_ Rexx. What OS and version of Rexx are you using?

Les
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

GaryT
windows 7 latest 32 bit rexx
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

LesK
Administrator
Regina or ooRexx, or something else?

Les
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

GaryT
ooRexx
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

LesK
Administrator
OORexx comes with excellent documentation. Look in

C: Program Files (x86)\ooRexx\doc

and you'll find: rexxpg.pdf

Chapter 3 - A Quick Tour of Traditional Rexx

will give you the basics of classic Rexx.

A more thorough tutorial for classic Rexx can be found at:

http://www.kyla.co.uk/other/rexx1.htm

 I found it by simply Googling 'rexx tutorial'. Lots of things to choose from! Remember, Rexx's roots are the
mainframe. Originally VM/CMS (now z/VM) and then MVS (now z/OS).

Les
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

GaryT
is that all?
Reply | Threaded
Open this post in threaded view
|

Re: how do you invoke a "Procedure"

LesK
Administrator
Huh? What else were you expecting?

Les

On 11/20/2013 12:26 PM, GaryT [via Rexx Language Association Forum] wrote:

>
>
> is that all?
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://rexx-language-association-forum.44760.x6.nabble.com/how-do-you-invoke-a-Procedure-tp1127p1149.html
> To start a new topic under Classic Rexx, email [hidden email]
> To unsubscribe from Rexx Language Association Forum, visit