Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

REXX: How to return multiple values from a function?

864 views
Skip to first unread message

Keith Bennett

unread,
Jan 31, 1995, 3:36:00 PM1/31/95
to
In order to conveniently manipulate structures in an array, I'm
storing each structure as a string. For each structure type I want
to have a Pack and Unpack function.

The Pack function is no problem; I pass several arguments (the
members, or fields, of the struct) and the function returns a single
string containing the entire structure.

The Unpack function presents a problem, though; I pass a single
string, but need the function to return several values. The best
method I can think of is to pass an array stem (or even several
variable names, one for each member). Then inside the unpack
function I would use interpret() to put values there. Is there a
better way?

Thanks for any help.
- Keith

--
--------------------------------------------------------------------------
Keith Bennett Bennett Business Solutions, Inc.
C++/C Software Development 1852 Middlebridge Drive
kben...@cpcug.org Silver Spring, MD USA 20906

Heinz Mueller

unread,
Feb 1, 1995, 8:14:21 AM2/1/95
to
* Reply to message in General.Rexx.Discussion

Hello General !

Replying to a message of General REXX Discussion List to Heinz Mueller:

GRDL> The Unpack function presents a problem, though; I pass a single
GRDL> string, but need the function to return several values. The best
GRDL> method I can think of is to pass an array stem (or even several
GRDL> variable names, one for each member). Then inside the unpack
GRDL> function I would use interpret() to put values there. Is there a
GRDL> better way?

Use fixed Fixed item - Length and
Parse Var String Part1 "+10" Part2 "+20" part3 "+10"

Or more convenient Use a Delimiter on packing e.g. "FF"X

which leads to

parse var String Part1 "ff"x part2 "ff"x part3

No real need for structures in Rexx just some phantasy :-)))

Note: you cannot easily store "FF"X in variable (e.g. delim) on the example
above.
In this case you would have to use Interpret.

As the "structures" you need are fixed the code can be fixed.

Another issue on your structures - problem.

Is there any need for garbage collect or a sorted Stem ??

You shouls consider the drop - function for deleting elements and storing a
Lokup
Table with numbers of deleted elements.

When you want to write the Stem you use to disk then you have 2 means to test
deleted elements
do i = 1 to Stem.0

if wordpos(i,LookupString) > 0 then iterate i
/* other chance: if Symbol(Stem.n.Member) = "LIT" then iterate i */

End i

No real need for Structure - handling again :-) Just some phantasy. :-)
A hard thing for C-programmers :-) (no insult meant just a observation in 20
Years of doing that job)

--=={Regards Heinz Mueller [Team OS/2 int.]}==--
--=={[c...@quattro.bb.bawue.de][hm...@ibm.net]}==--

Peter Buck

unread,
Feb 1, 1995, 8:21:26 AM2/1/95
to
Pick a delimiter char which will never appear in your data, return a
single variable made up of the pieces concatenated with the delimiter
between them. Then call unpack as follows:

parse value unpack(struct) with a"|"b"|"c"|"d"|"e /* | is delimiter
*/

Of course in that case you really don't need an unpack function, do you.
______________________________ Reply Separator _________________________________
Subject: REXX: How to return multiple values from a function?
Author: General REXX Discussion List <REXX...@vm.gmd.de> at NOTE
Date: 1/31/95 8:13 PM


In order to conveniently manipulate structures in an array, I'm
storing each structure as a string. For each structure type I want
to have a Pack and Unpack function.

The Pack function is no problem; I pass several arguments (the
members, or fields, of the struct) and the function returns a single
string containing the entire structure.

The Unpack function presents a problem, though; I pass a single


string, but need the function to return several values. The best

method I can think of is to pass an array stem (or even several

variable names, one for each member). Then inside the unpack

function I would use interpret() to put values there. Is there a

dsda...@mail.rain.org

unread,
Feb 1, 1995, 12:45:49 AM2/1/95
to
>
>The Unpack function presents a problem, though; I pass a single
>string, but need the function to return several values. The best
>method I can think of is to pass an array stem (or even several
>variable names, one for each member). Then inside the unpack
>function I would use interpret() to put values there. Is there a
>better way?
>
You could also push your RETURN values onto a named queue then just return the
queuename and retreive your multiple values from there.

_ _
\ \ \ Doug Darrow \ $ 0.02 (two cents worth)
)=========================> - 0.01 (for your thoughts)
/_/_/ <dsda...@rain.org> / = 0.01 (value of post 8-)

Jason Tiller

unread,
Jan 31, 1995, 7:30:24 PM1/31/95
to
In <3gm6vg$f...@cpcug.org>, kben...@cpcug.org (Keith Bennett) writes:

Hi, Keith, :)

>The Unpack function presents a problem, though; I pass a single
>string, but need the function to return several values. The best
>method I can think of is to pass an array stem (or even several
>variable names, one for each member). Then inside the unpack
>function I would use interpret() to put values there. Is there a
>better way?

What do these "structured strings" look like? How does the UnPack
function work? It's obviously more complicated than a:

do i = 1 to Words(PackString)
UnpackStem.i = Word(PackString, i)
end
UnpackStem.0 = i -1

right? As far as returning multiple values, no, there really is no
better way. You could push 'em all on to a queue and then stuff 'em
into a stem from there (I've done this - most useful with multiple
strings with spaces). Seems the interpret command might work, but
you can't "procedure" the UnPack routine, which is a bummer (unless
you *always* return some generic stem name and then expose that).

This sounds interesting. Keith... you asked about RexxLib stuff a
few days ago, right? I'll follow up this with an e-mail; I think I
have some ideas about the sorting routine you were talking about in
that previous article.

Good luck. :>

>Thanks for any help.
>- Keith

---
/============\ Jason Tiller /======================================\
| Welcome to | | Voyager 2 emits less power than your |
| -> JPL <-/=======================\refrigerator light bulb - yet we |
\==========| Do *you* know where |track it 6.4 *billion* km away! |
The | your spacecraft is? |==================================/
DSN \=======================/ ** jti...@ringer.jpl.nasa.gov **

markb)

unread,
Feb 1, 1995, 6:51:16 AM2/1/95
to
In article <3gm6vg$f...@cpcug.org> kben...@cpcug.org "Keith Bennett" writes:

> In order to conveniently manipulate structures in an array, I'm
> storing each structure as a string. For each structure type I want
> to have a Pack and Unpack function.
>
> The Pack function is no problem; I pass several arguments (the
> members, or fields, of the struct) and the function returns a single
> string containing the entire structure.
>
> The Unpack function presents a problem, though; I pass a single
> string, but need the function to return several values. The best
> method I can think of is to pass an array stem (or even several
> variable names, one for each member). Then inside the unpack
> function I would use interpret() to put values there. Is there a
> better way?
>
> Thanks for any help.
> - Keith

I seem to be missing something complicated, here and in your previous
posting.

Neither Pack nor Unpack should be difficult enough to need a sub-routine.

What is wrong with:

packed_string = tcpip.host"&"tcpip.alias"&"tcpip..... /* packer */

parse var packed_string new.host "&" new.alias "&" new..... /*unpacker*/

I haven`t tried it, but I think it will work.

(you need to be sure that & is not a value that will appear in any
of the strings)

General advice when writing Rexx is to forget all other paradigms ;>}

--
ma...@waif.demon.co.uk
"All the world`s a string, And all the men and women merely parsers:"

Mik Clarke

unread,
Feb 1, 1995, 8:14:44 AM2/1/95
to
kben...@cpcug.org (Keith Bennett) writes:

>In order to conveniently manipulate structures in an array, I'm
>storing each structure as a string. For each structure type I want
>to have a Pack and Unpack function.

>The Pack function is no problem; I pass several arguments (the
>members, or fields, of the struct) and the function returns a single
>string containing the entire structure.

>The Unpack function presents a problem, though; I pass a single
>string, but need the function to return several values. The best
>method I can think of is to pass an array stem (or even several
>variable names, one for each member). Then inside the unpack
>function I would use interpret() to put values there. Is there a
>better way?

Assuming you can't live with them always being unpacked to the same
array, then your method is about the best way of doing it. Use value
rather than interpret if your level of REXX supports the second parm on
it. One thing to consider. If your packing routine is doing something
like:

pack:
line = ''
do i = 1 to arg()
line = line c2x(arg(i))
end
return

The the n'th value of the array is simply x2c(word(packed_line,n)). Might
be simpler just to code this inline.

I have seen the c2x trick used to return multiple values from a function,
but the caller then has to have un unpack loop following the function call...

Mik

Ty Halderman

unread,
Feb 6, 1995, 9:54:42 PM2/6/95
to
In article <2f2f...@f90.n420.z42.fidonet.org>, c...@QUATTRO.BB.BAWUE.DE
says...
>
>[snip]

>Or more convenient Use a Delimiter on packing e.g. "FF"X
>which leads to
>parse var String Part1 "ff"x part2 "ff"x part3
>
>No real need for structures in Rexx just some phantasy :-)))
>Note: you cannot easily store "FF"X in variable (e.g. delim) on the
example
>above.
>In this case you would have to use Interpret.

can't you use:

delim = "ff"x
parse var string part1 (delim) part2 (delim) part3...

or am I spoiled with a "newer" REXX parse spec?

Actually I load the stuff in a stem frequently with that:

ix = 0
do while length(string) > 0
ix = ix + 1
parse var string part.ix (delim) string
end
part.0 = ix /* habit: count in subscript zero */

--
=-Ty Halderman ( thl...@sam.neosoft.com )
Hobbies: Doom, Eek the Cat, Doom, Python (Monty), Doom, and Doom.
* No one is completely useless. They can always be used as a *
* bad example. -- WCFields *

Peter McKellar

unread,
Feb 7, 1995, 5:24:00 PM2/7/95
to
Ty,
I prefer to compound my DO statements in a case like that quoted:

> ix = 0
> do while length(string) > 0
> ix = ix + 1
> parse var string part.ix (delim) string
> end
> part.0 = ix /* habit: count in subscript zero */

would become:

Do ix = 1 While Length(string) > 0
Parse Var string part.ix (delim) string
End
part.0 = ix /* GOOD habit */

I don't know how this goes for performance, but it saves a couple of lines.

Peter McKellar

Jason Tiller

unread,
Feb 7, 1995, 6:03:29 PM2/7/95
to
In <REXXLIST%9502070...@UGA.CC.UGA.EDU>, Peter McKellar <p_mck...@VNET.IBM.COM> writes:
>Ty,
>I prefer to compound my DO statements in a case like that quoted:

[previous example deleted]

>Do ix = 1 While Length(string) > 0
> Parse Var string part.ix (delim) string
>End
>part.0 = ix /* GOOD habit */

Careful, careful, careful! Ty's original code results in one *fewer*
lines being read than your code! Either use ix - 1 for the array.0
storage, or set ix = 0 for your initial value (which is common sense,
since string may have a length of 0 initially).

I like this, actually. I've always used Ty's method, but I think I'll
try yours. :>

>I don't know how this goes for performance, but it saves a couple of lines.
>
>Peter McKellar

---

Jason Tiller

unread,
Feb 8, 1995, 9:28:17 PM2/8/95
to
In <3h8u81$3...@lo-fan.jpl.nasa.gov>, jti...@ringer.jpl.nasa.gov (Jason Tiller) writes:
>In <REXXLIST%9502070...@UGA.CC.UGA.EDU>, Peter McKellar <p_mck...@VNET.IBM.COM> writes:

>>Do ix = 1 While Length(string) > 0
>> Parse Var string part.ix (delim) string
>>End
>>part.0 = ix /* GOOD habit */

>Careful, careful, careful! Ty's original code results in one *fewer*
>lines being read than your code! Either use ix - 1 for the array.0
>storage, or set ix = 0 for your initial value (which is common sense,

^^^^^^ sorry, I goofed


>since string may have a length of 0 initially).

DOH! Sorry - obviously, you wouldn't want to start at ix = 0. I
think you need "part.0 = ix - 1" at the end.

Keith Bennett

unread,
Feb 9, 1995, 7:42:29 AM2/9/95
to
In article <REXXLIST%9502070...@uga.cc.uga.edu>,

Peter McKellar <p_mck...@VNET.IBM.COM> wrote:
>Ty,
>I prefer to compound my DO statements in a case like that quoted:
>
>> ix = 0
>> do while length(string) > 0
>> ix = ix + 1
>> parse var string part.ix (delim) string
>> end
>> part.0 = ix /* habit: count in subscript zero */
>
>would become:
>
>Do ix = 1 While Length(string) > 0
> Parse Var string part.ix (delim) string
>End
>part.0 = ix /* GOOD habit */
>
>I don't know how this goes for performance, but it saves a couple of lines.
>
>Peter McKellar


Peter -

Where do you increment ix?

0 new messages