** This thread discusses the article: %XFOOT with %LEN **
First, can you specify a common situation where the sum of the number of digits in the array might be useful? Second, why not code "%len(qty)*%dim(qty)"? That would not only be clearer, but should also be faster. Cheers! Hans
** This thread discusses the article: %XFOOT with %LEN **
Bob, That technique is awesome. Good finding, I am sure I will find a use for it someday. Thanks, Michael P.
** This thread discusses the article: %XFOOT with %LEN **
That "anomaly" is very obscure, and not everyone will understand the code. I have to go with Hans on this one (though I think he meant %elem, not %dim). It is much clearer.
** This thread discusses the article: %XFOOT with %LEN **
What I find interesting is the returned value(s) of the %len BIF. Or any expression containing arrays. I believe the expression %len(ary)*%elem(ary) would just return a numeric array of lengths with each element multiplied by the number of elements in the array. %xfoot is just doing what it is designed to do; summarize numeric arrays. The magic is %len.
** This thread discusses the article: %XFOOT with %LEN **
Paul wrote: "I believe the expression %len(ary)*%elem(ary) would just return a numeric array of lengths with each element multiplied by the number of elements in the array." Your belief is incorrect. For numeric arrays, the expression "%len(ary)*%elem(ary)" multiplies a scalar constant by a scalar constant. It's been too long for me to remember the details, but the compiler might even do the computation at compile-time. (With optimization, the back-end should figure that out easily anyways.) Cheers! Hans
** This thread discusses the article: %XFOOT with %LEN **
Nope. %len(ary) gets a diagnostic about a missing index. But %len(ary(1)) * %elem(ary) would work for anything with fixed-length, and indeed be more efficient than %xfoot. For varying fields, %xfoot(%len(ary)) is exactly what's needed. It's not really an anomaly. It's a normal feature of RPG that %bif(array) returns an array (except for a couple of builtin functions like %SIZE and sometimes %ADDR). %subst(someArray : 2 : 5) returns an array of substrings, which you could assign to another array eval someOtherArray = %subst(someArray : 2 : 5)
** This thread discusses the article: %XFOOT with %LEN **
You're right. I realized my mistake on the drive home last night. Yes, "%len(ary(1))*%elem(ary)" is what I should have recommended. It may be a normal feature of the language, but the inconsistency still looks goofy (IMO). (Although I can see some potential use for "%xfoot(%len(ary))" for char varying arrays, I still don't see much point for anything else.) Cheers! Hans
** This thread discusses the article: %XFOOT with %LEN **
Array in array out for most all bifs. Makes sense. So for fixed length arrays we can do: totLen = %xfoot(%len(%trim(names))) or for decimal arrays: totLen = %xfoot(%len(%char(amounts))) totLen = %xfoot(%len(%trim(%editc(amounts:'Z')))) evalr array = %char(amounts) I like it.
Comment