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
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]}==--
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
_ _
\ \ \ Doug Darrow \ $ 0.02 (two cents worth)
)=========================> - 0.01 (for your thoughts)
/_/_/ <dsda...@rain.org> / = 0.01 (value of post 8-)
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 **
> 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:"
>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
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 *
> 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
[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
---
>>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.
Peter -
Where do you increment ix?