home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!TOROLAB6.VNET.IBM.COM!LANSCHE
- From: LANSCHE@TOROLAB6.VNET.IBM.COM ("Martin Lansche")
- Newsgroups: comp.os.os2.misc
- Subject: RE: Stem Variables as Arguments
- Message-ID: <9208131845.AA12317@ucbvax.Berkeley.EDU>
- Date: 13 Aug 92 17:09:24 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Lines: 57
-
- Michael, Jean-Pierre,
- A long time ago I suffered through the same dilemma. There used to be
- a very ugly way to do this via
-
- myfunc: Interpret "PROCEDURE EXPOSE" arg()
-
- which violated the REXX language definition, but worked until about 1989
- - they enforced the language definition in the CMS version of REXX then.
- So I was able to get around it using a more elegant trick. The central
- idea is that all of the stem variables that you could possibly want to
- use as an arguement to functions should be placed in a "SUPER-STEM".
- For instance, instead of having
- Opts.1 = "A"
- Opts.2 = "B"
- &c.
- code it instead as
- Stem.Opts.1 = "A"
- Stem.Opts.2 = "B"
- Then your can use PROCEDURE EXPOSE STEM., and pass as an argument the
- 1st level of indirection which, in essence, is your passed Stem variable.
- Here is Michael's sample rewritten with this technique. Run with
- "Trace i" to see it at work.
-
- Cheers,
- Martin Lansche Lansche@Torolab6.vnet.ibm.com
-
- =========== cut here =============
- /* Init the stem var. */
- Stem. = ''
- Stem.Opts.Label = 'Select an option A-C, X'
- Stem.Opts.0 = 4 /* No. options */
- Stem.Opts.1 = 'A'
- Stem.Opts.2 = 'B'
- Stem.Opts.3 = 'C'
- Stem.Opts.4 = 'X'
-
- Choice = GetChoice("Opts")
- exit
- /* ... */
-
- GetChoice: PROCEDURE EXPOSE STEM.
- ARG name /* Stem var with options */
-
- SAY Stem.name.Label
- PULL Resp
- DO i = 1 TO Stem.name.0
- IF Resp = Stem.name.i THEN
- LEAVE
- END /* i */
-
- IF i = Stem.name.0 + 1 THEN /* Default is Stem.1 */
- RETURN Stem.name.1
-
- RETURN Stem.name.i
-
- /* End of example */
-
-