The DO...OVER statement allows one to iterate over a collection. To do so a
MAKEARRAY is requested
and the resulting array is then iterated over.
It seems, that the code in DO...OVER does not send the MAKEARRAY message, if it
does not find that
method in the receiver object, irrespectible whether an UNKNOWN method is
available that may step in
and return that array upon request.
Here is a Rexx program demonstrating this problem, bug:
t=.test~new tArr=t~makearray~toString(,"/") say "tArr:" tArr do o over t
say o end say "---"
u=.uuu~new uArr=u~makearray~toString(,"/") say "uArr:" uArr do o over u say
o end say "---" *::class test ::method makearray*return ("one", "two", "three")
*::class uuu****::method unknown*
use arg methName, methArgs /*if methName="MAKEARRAY" then return ("one",
"two", "three")*/ say
"in" self"::unknown, about to raise a syntax condition" raise syntax 98.913
array (self)
The class "TEST" implements the MAKEARRAY method and the DO...OVER succeeds.
The class "UUU" does not implement the MAKEARRAY method, but an UNKNOWN method
that returns an
array, if a MAKEARRAY message was received. Here, DO...OVER causes a 98.913
syntax error, which
aborts the program!
Here is the output of running the above program:
F:\test\oorexx\makearray>test1 tArr: one/two/three one two three --- uArr:
one/two/three 13 *-*
do o over u Error 98 running F:\test\oorexx\makearray\test1.rex line 13:
Execution error. Error
98.913: Unable to convert object "an UUU" to a single-dimensional array
value.
It may be the case that the interpreter tries to optimize by checking for the
existence of a
MAKEARRAY method in the receiving object and if not found short-circuiting by
raising the syntax
error. Instead it should let the UNKNOWN mechanism to get exercised, such that
it becomes possible
to delegate the execution of such unknown messages (like MAKEARRAY in the class
UUU above) by other
code, which is the purpose of the UNKNOWN mechanism in the first place.
This is with ooRexx 5.0.0 beta, not sure about previous versions.
If there are no counter arguments, then I will file a bug report for this in
the tracker.
---rony
P.S.: "DO WITH index i and item o" works by supplying the SUPPLIER method
explicitly or implicitly
by the UNKNOWN method. Here is an example for that variant:
t=.test~new say "tArr:" tArr do with index idx item o over t say "index:"
idx "item:" o end say
"---" u=.uuu~new say "uArr:" uArr do with index idx item o over u say
"index:" idx "item:" o end
say "---" *::class test* *::method supplier* return .supplier~new((1,2,3),
("one", "two",
"three")) *::class uuu****::method unknown* use arg methName, methArgs /*if
methName="SUPPLIER"
then return .supplier~new((1,2,3), ("one", "two", "three"))*/ say "in"
self"::unknown, about to
raise a syntax condition" raise syntax 98.913 array (self)
Output (no runtime error):
F:\test\oorexx\makearray>test2 tArr: TARR index: one item: 1 index: two
item: 2 index: three
item: 3 --- uArr: UARR index: one item: 1 index: two item: 2 index: three
item: 3 ---
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel