On 5/26/2020 2:19 PM, Don Wiss wrote:
> I have succeeded in converting from APL to VBA all of the code that is used
> to create and maintain two of my websites. This includes my HTML sitemap
> creating program. With lots of functions with names like APL primitives, it
> is slow. But functionality it is better than before.
>
> There is one thing I could not replicate in the conversion. In one place I
> want to sort the numbers after the letters. Trivial, of course, in APL. I
> only care about the 7th character in, so I could look for this block and
> swap the ones starting with letters and numbers. But not very elegant.
>
> Is it possible to simulate a dyadic gradeup? Or should I go ahead and write
> the code that swaps the blocks?
One way to handle Dyadic Grade (L⍋R, on chars) is with Translate Tables.
Use the same code you have for Monadic Grade. Pre-compute Translate
Table(s), one per dimension of L. Let's assume L is a vector for
simplicity, and we'll treat the chars as unsigned one-byte numbers so
that the TTs are each 256 bytes long.
* Initialize TT with 256⍴255.
* Loop through L[I] and set TT[L[I]]⌊←I
* Now run through your existing Monadic Grade algorithm. Where you
previously compared R[I] and R[J] (essentially, you exchanged if
1=×R[I]-R[J]), now exchange if 1=×TT[R[I]]-TT[R[J]]. Here's a feature I
omitted from the previous algorithm, if the signum in the above
expression returns 0, then exchange iff 1=×I-J so as to obtain a stable
grade. The BubbleSort you implemented doesn't need this, but (say) a
ShellSort does.
* If L is a higher rank array (say 3D), then construct a 3-row matrix TT
where each row is calculated from three nested FOR loops. If you want
to see how that works, see below.
Then for K∊⍳⍴⍴L, exchange if 1=×TT[K;][R[I]]-TT[K;][R[J]]. If the
signum in this expression returns 0, try the next row in TT. If all the
signums return 0, then exchange iff 1=×I-J.
* Alternatively, you can download a ZIP archive with implementations of
the construction of the Translate Tables in C, Perl, and PHP from
http://www.sudleyplace.com/APL/aplcmp.zip
as referenced in "A Glitch In Grade",
http://www.sudleyplace.com/APL/GlitchInGrade.ahtml.
--
_________________________________________
Bob Smith -- bsmith@sudleydeplacespam.com
http://www.sudleyplace.com - http://www.nars2000.org
To reply to me directly, delete "despam".
|
|