Hi Josep Maria,
On 09.03.2025 12:19, Josep Maria Blasco wrote:
Missatge de Rony G. Flatscher <rony.flatsc...@wu.ac.at> del dia dg., 9 de març
2025 a les 11:40:
1) ad stem arrays
==============
Stem arrays have been conceived and used since the inception of Rexx.
The pattern is simple: the tail is an integer number from 1 on, the tail
with the value 0
keeps the current number of total stem array elements. E.g.:
a.1="one"
a.2="two"
a.0=2
say "there are" a.0 "items"
Turning such a stem array into an ooRexx array should yield an array that
omits the element
with the tail 0 and uses the tail's number as index in the ooRexx array.
E.g. turning the
above stem array into an ooRexx array:
a[1]="one"
a[2]="two"
say "there are" a~itmes "items"
1a) In order to create an ooRexx array from a stem array the following
method should be added
to the stem class:
makeArrayFromStemArray
This name makes it clear that a stem array is to be processed and that the
resulting array
should not have the stem value with the tail 0.
(The existting stem method makeArray continues to create an array that
represents all tails of
a stem, including a tail with the value 0.)
I'm not sure that using "makeXXX" for the message names is a good idea, because the request method
of the Object class uses the "make" pattern for class conversions.
Yes, that is the reason why using that name.
I'd also try to choose a shorter name (long names are difficult to remember).
Yes, I can understand that. In this case there is an important difference between a stem (may have
any number of tail values, not necessarily following the stem array pattern) and a stem that follows
the stem array pattern. There is already a makeArray method defined that works for any stem, so to
make it clear that a specific type of stems get processed the idea to add that information to the
name ("makeArray"..."fromStemArray").
But of course any other, shorter, better name would be preferrable.
Some things that should be defined:
* What happens when not all tails have a value? For example, if s.=
'Default", s.0 = 3, s.1 =
'X", s.2 does not have a value, s.3 = "Z", and a is the converted array,
what should be the
value of a[2]? Both "Default" and .Nil are reasonable answers to this
question.
Good question. My take was, if there is no tail existing, then there is no reason to add it to the
array. :)
However, it may be important to use the default or a user-supplied value like .nil instead. This
could be done with an optional option. ;)
However, if making an option available then the request protocol could not be applied and then the
name needs to be changed. In that case the name could be changed to something like
fromStemArray(['DefaultValue' | .nil [,explicitDefaultvalue]])
where the first argument indicates to use the stem's default value if "D"(efaultValue) given, or
.nil, if .nil given. If the the second argument is supplied, then its value gets used in place of
the default value for missing stem array elements.
* What happens when the stem has values that are not part of the array, like s.this =
"that"?
* When s.0 is not a positive integer, a syntax error should be raised.
1b) In order to create a stem from an ooRexx array the following method
should be added to the
array class:
makeStemArray
This name makes it clear that a stem array is to be created from the array
items (using the
array index values as tails) and adding the 0 tail to indicate the number
of stem elements.
Maybe in this case we could use makeStem directly, as there is no prior method with that name?
Also: what happens when the array is multi-dimensional? One would think of using several stem
indexes, as in s.1.4.2 = "value", but then it becomes unclear where to store the dimensions.
ATM, this would be intended for single dimensioned arrays only. When creating a stem from an array
there are two options: create a stem using the index value as the tail value, but create no stem
with a tail of zero; or, add the zero tail value to the stem indicating the highest used index
value. Also, if there is no array entry (hasIndex would return .false) no stem variable should be
created.
---
2) ad using the array class for reading and writing files/streams directly
==========================================================
The ooRexx stream class has a method arrayin to allow reading the content
of a stream into an
ooRexx array, and arrayout to write the content of an array to a stream. In
order to use these
methods a stream instance must be created first before being able to use
the arrayin and
arrayout methods and closing the stream thereafter. As the purpose of these
two methods is to
simply get the content into and from an array, it may be cumbersome to
explicitly have to open
and close streams in order to just read into or write the content of an
array.
In order to forego the need to create stream instances in order to read the
content into an
array or an array into a stream or file two class methods for the ooRexx
array class are proposed:
2a) In order to read the content of a stream or a file with a single
message into an array the
following method should be added to the array class:
arrayin(filename|stream|file[, Lines|chars)
This allows for supplying either a filename (string), an instance of .File
or .Stream and
optionally "Lines" (default, one array element per text line) or "chars"
(one array element
per character).
2b) In order to write the content of an array to a file or a stream the
following method
should be added to the array class:
arrayOut(filename|stream|file[, Lines|chars)
This allows for supplying either a filename (string), an instance of .File
or .Stream and
optionally "Lines" (default, a text line per per array element) or "chars"
(the characters of
all array elements, without appending endoflines).
+1
---rony
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel