home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / amiga / programm / 12956 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  2.4 KB

  1. Path: sparky!uunet!mcsun!uknet!stl!bmdhh243!bedford
  2. From: bedford@bnr.ca (Richard Bedford)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: ARexx stem variables (records) vs. function return values?
  5. Message-ID: <1992Sep01.161540.13958@bnr.uk>
  6. Date: 1 Sep 92 16:15:40 GMT
  7. References: <52692@dime.cs.umass.edu>
  8. Sender: news@bnr.uk (News Administrator)
  9. Organization: BNR Europe Ltd, Maidenhead, UK
  10. Lines: 47
  11. Nntp-Posting-Host: bmdhh9
  12. X-Newsreader: Tin 1.1 PL5
  13.  
  14. You have the wrong idea about stem variables. They are not structures or 
  15. records, but the way REXX implements arrays. REXX has no implementation for
  16. structures or records, since everything, including numbers, is stored as
  17. strings. You can not pass a stem variable back from a return statement, since
  18. return can only pass back a single value. If you need to pass more than one
  19. value back, concatenate the values together and parse the result. For example:
  20.  
  21.         parse value returnStuff() with person.firstname person.lastname
  22.         SAY person.firstname person.lastname
  23.         EXIT
  24.  
  25.         ReturnStuff: PROCEDURE
  26.                 guy.name = "Harry"
  27.                 guy.lastname = "Hosehead"
  28.                 RETURN guy.name||' '||guy.lastname
  29.  
  30. If you need spaces in the values to be passed back, change the character 
  31. between the concatenation marks to some other character that will not appear
  32. in the result and use this as a parsing delimiter in the parse command.
  33. For example:
  34.  
  35.         sep = d2c(0)
  36.         parse value returnStuff() with person.firstname (sep) person.lastname
  37.         SAY person.firstname person.lastname
  38.         EXIT
  39.  
  40.         ReturnStuff: PROCEDURE EXPOSE sep
  41.                 guy.name = "Harry"
  42.                 guy.lastname = "Hosehead"
  43.                 RETURN guy.name||sep||guy.lastname
  44.  
  45. One other thing to note, NEVER declare a new variable with the same name as
  46. a name used to the right of the period in a stem variable. You will end up 
  47. with some very strange results. For example:
  48.  
  49.        person.firstname = 'Harry'
  50.        person.lastname = 'Hosehead'
  51.        say person.firstname     -> gives 'Harry'
  52.        firstname = 'lastname'
  53.        say person.firstname     -> gives 'PERSON.lastname'
  54.  
  55. This is because lastname in person.lastname gets replaced with it's value
  56. and therefore REXX thinks you are asking for the value of person.lastname. But
  57. REXX only replaces names of varibles with their value once and you therefore
  58. get 'PERSON.lastname'.
  59.  
  60. Richard Bedford
  61.