home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / rexx / 709 < prev    next >
Encoding:
Text File  |  1992-08-13  |  6.0 KB  |  158 lines

  1. Newsgroups: comp.lang.rexx
  2. Path: sparky!uunet!mcsun!sunic!aun.uninett.no!ugle.unit.no!ugle!anders
  3. From: anders@lise7.lise.unit.no (Anders Christensen)
  4. Subject: Re: Stem vars as arguments?
  5. In-Reply-To: jpr@sun4.lri.fr's message of 13 Aug 92 09:14:49 GMT
  6. Message-ID: <ANDERS.92Aug13221602@lise7.lise.unit.no>
  7. Sender: news@ugle.unit.no (NetNews Administrator)
  8. Organization: /home/flipper/anders/.organization
  9. References: <ednstras.713591629@kraken> <1992Aug13.091449.11425@lri.fr>
  10. Date: 13 Aug 92 22:16:02
  11. Lines: 145
  12.  
  13. Warning: I deleted comp.os.os2.misc from "Newgroups:"
  14.  
  15. In article <1992Aug13.091449.11425@lri.fr> jpr@sun4.lri.fr (Jean-Pierre Riviere) writes:
  16. > In article <ednstras.713591629@kraken>, ednstras@kraken.itc.gu.edu.au
  17. > (Michael Strasser) writes:
  18. > |> [...]  I would like to be able to use a stem variable as an
  19. > |> argument to an internal procedure, but my attempts have failed so
  20. > |> far.
  21. > I too have encountered similar problems of which I wanted to post today...
  22.  
  23. When using a stem variable as parameter, only the 'default' value will
  24. be used. You can never use a collection of variables as parameters.
  25. Instead, use:
  26.  
  27.     subfunc: procedure expose stem.
  28.                                  ^^^ note the dot.
  29.  
  30.  1)  "stem" refers to the simple variable "stem", 
  31.  
  32.  2)  "stem." refers to the collection of all compond variables that 
  33.      starts with the head "stem.".
  34.  
  35.  3)  "stem.1" refers to one particular variable in the collection of 
  36.      variables that starts with the head "stem."
  37.  
  38. > GetChoice: PROCEDURE EXPOSE Opts.0 Opts.1 Opts.2 Opts.3 Opts.4
  39.  
  40. Or maybe better (assuming that you want to expose variables like
  41. Opts.5, Opts.6 ... Opts.whatever):
  42.  
  43.   GetChoice: PROCEDURE EXPOSE Opts.
  44.  
  45. But note the following trap:
  46.  
  47.   GetChoice: PROCEDURE guy.name.
  48.  
  49. The two clauses in the last example will expose the compound variable
  50. named "guy.name.", that is the variable having the head "guy." and the
  51. tail "name.". It will _NOT_ expose any other variable, and in
  52. particular not variables like "guy.name.mail" or "guy.name.passwd". In
  53. other words, _only_ the first dot in a compound variable name is
  54. 'magic'.
  55.  
  56. Also note another potensial dangerous trap in the scoping of Rexx
  57. variables. Suppose you have a main program, and two subroutines: A and
  58. B. The main program calls A, and A calls B. B is to access a variable
  59. set by the main program. If B is to get that variable, A must either
  60. not use PROCEDURE, or it must use PROCEDURE and expose that variable:
  61.  
  62.     var = foobar ;
  63.     call A
  64.     exit
  65.  
  66.     A: procedure expose var   /* Must expose 'var' if 'procedure ... */
  67.        call B                            /* ... is to be used at all */
  68.        return
  69.  
  70.     B: procedure expose var
  71.        say 'var is now' var
  72.        return
  73.  
  74. If A does not expose 'var', it will not matter whether B expose it or
  75. not, since A has blocked the definition. I believe that the EXPOSE on
  76. stems to expose collections of variables have been a feature in Rexx
  77. for some time, and that most interpreters have these feature.
  78.  
  79. > So how would it best to deal with the construction of "objects" ?
  80. > For instance, guy is the class name of the object, and name is a variable
  81. > that I use to identify the guy in guy.name Knowing thew guy I can then
  82. > allow him a password for instance : guy.name.passwd
  83. > But If I have to declare guy.name.passwd and not change name nor passwd
  84. > in any procedure I will soon come to BIG PUZZLES too!
  85.  
  86. You don't declare any variables in rexx. I think your use of compound
  87. variables here have more in common with (nested) structs in C, than
  88. with actual objects (as in OO-programming). 
  89.  
  90. > Anothe problem is that I have difficulty with avoidind painful select loop
  91. > with construct like :
  92. > /* assgin name of functions to stem var */
  93. > choice.quit = myQUIT
  94. > choice.read = myREAD
  95. > choice.write = myWRITE
  96. > say "choice ?"
  97. > parse pull this
  98. > call choice.this /* doesn't work - I tried variations but to no avail
  99. > (value, interpret) */
  100.  
  101. First, remember that the tail part of compound variables is case
  102. sensitive (actually the head part is that too, but you'll almost never
  103. crash into that). Suppose you had the following code:
  104.  
  105.     lower =   'foobar'
  106.     upper =   'FOOBAR'
  107.     space = '  foobar  '
  108.  
  109. Now, the variables foo.lower, foo.upper and foo.space would be three
  110. completely different and disctinct variables, and the variable
  111. foo.foobar would be identical to the variable foo.upper (supposing
  112. that foobar is an unset variable). In your example, the variable
  113. called 'CHOICE.WRITE' gets the value 'MYREAD', while you (assuming
  114. that you type in 'write' in lower case) are trying to call the routine
  115. 'CHOICE.write'.
  116.  
  117. Then, the dot-magic in compound names only works for variables, never
  118. for labels, since labels are simple symbols. I.e. the dot is not a
  119. legal character in a label. To solve your problem, you can rewrite the
  120. CALL-clause:
  121.  
  122.     interpret 'call' choice.this
  123.  
  124. (btw, using this solution, you don't have to bother about case at all,
  125. since the parameter expression to INTERPRET is parsed and the name of
  126. the label is transformed into upper case. 
  127.  
  128. Somebody mentioned the indirect exposing of variables, as in:
  129.  
  130.     vars = "foo bar"
  131.     call subfunc
  132.     exit
  133.  
  134.     subfunc procedure expose one two (vars) three
  135.        /* exposes 'one', 'two', 'three', 'foo' and 'bar'
  136.        return
  137.  
  138. This is a new Rexx language level 4.00 feature, but in older
  139. interpreters the same effect _might_ be obtained through the use of a
  140. very dirty programming trick (people who don't want their mind
  141. littered with dirty programming tricks should stop reading now!)
  142. Define 'subfunc' as:
  143.  
  144.     subfunc interpret 'procedure expose one two' vars 'three'
  145.  
  146. (Yes, I knew you would read on...) This is not allowed in Rexx
  147. language level 4.00, since 'procedure' must be the first statement
  148. after the label, if it is to be used in a subroutine. That ease the
  149. inplementation of compilers, but I can't see any reason why an
  150. interpreters should not allow the programming trick above. The
  151. interpret clause is a magnificent tool :-)
  152.  
  153. -anders
  154.  
  155. PS: I only got half the articles in this thread, so I hope I didn't
  156.     repeat anything already said ..
  157.