home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!stl!bmdhh243!bedford
- From: bedford@bnr.ca (Richard Bedford)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: ARexx stem variables (records) vs. function return values?
- Message-ID: <1992Sep01.161540.13958@bnr.uk>
- Date: 1 Sep 92 16:15:40 GMT
- References: <52692@dime.cs.umass.edu>
- Sender: news@bnr.uk (News Administrator)
- Organization: BNR Europe Ltd, Maidenhead, UK
- Lines: 47
- Nntp-Posting-Host: bmdhh9
- X-Newsreader: Tin 1.1 PL5
-
- You have the wrong idea about stem variables. They are not structures or
- records, but the way REXX implements arrays. REXX has no implementation for
- structures or records, since everything, including numbers, is stored as
- strings. You can not pass a stem variable back from a return statement, since
- return can only pass back a single value. If you need to pass more than one
- value back, concatenate the values together and parse the result. For example:
-
- parse value returnStuff() with person.firstname person.lastname
- SAY person.firstname person.lastname
- EXIT
-
- ReturnStuff: PROCEDURE
- guy.name = "Harry"
- guy.lastname = "Hosehead"
- RETURN guy.name||' '||guy.lastname
-
- If you need spaces in the values to be passed back, change the character
- between the concatenation marks to some other character that will not appear
- in the result and use this as a parsing delimiter in the parse command.
- For example:
-
- sep = d2c(0)
- parse value returnStuff() with person.firstname (sep) person.lastname
- SAY person.firstname person.lastname
- EXIT
-
- ReturnStuff: PROCEDURE EXPOSE sep
- guy.name = "Harry"
- guy.lastname = "Hosehead"
- RETURN guy.name||sep||guy.lastname
-
- One other thing to note, NEVER declare a new variable with the same name as
- a name used to the right of the period in a stem variable. You will end up
- with some very strange results. For example:
-
- person.firstname = 'Harry'
- person.lastname = 'Hosehead'
- say person.firstname -> gives 'Harry'
- firstname = 'lastname'
- say person.firstname -> gives 'PERSON.lastname'
-
- This is because lastname in person.lastname gets replaced with it's value
- and therefore REXX thinks you are asking for the value of person.lastname. But
- REXX only replaces names of varibles with their value once and you therefore
- get 'PERSON.lastname'.
-
- Richard Bedford
-