How to Sort the Headers of the Methods ?

Writing and using Classes in Dyalog APL
Post Reply
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

How to Sort the Headers of the Methods ?

Post by PGilbert »

I personnaly like to have the local variables names in the header of a function sorted. I can do this with this function:

Code: Select all

 r←SortHeader fn_name;header;inter;nr;vars
 ⍝ Sort the Header of a Function
 ⍝
 ⍝ fn_name = Function Name

 ⍝ Nested Representation of Function
 nr←⎕NR fn_name

 ⍝ Removes the extra Blanks at the End of each line of the Function
 nr←(-¯1+(⌽¨' '=¨nr)⍳¨0)↓¨nr

 ⍝ Extract the Header of the Function
 header←1⊃nr

 ⍝ Check if there is local variables to sort in header
 :If ~';'∊header
     ⍝ no ';' in header. Return without fixing the function.
     r←'' ⋄ →0
 :Else
     ⍝ There is local variables in Header
     ⍝ Split the Header
     vars←(header⍳';')↓header

     ⍝ Sort the variables
     vars←';'{⎕ML←1 ⋄ ↑1↓¨(1,⍺=⍵)⊂⍺,⍵}(vars~' ')
     vars←vars[⎕AV⍋vars;]
     vars←(,';',vars)~' '

     ⍝ Reassemble the header
     header←((¯1+header⍳';')↑header),vars

     ⍝ Insert the Sorted Header in ⎕NR of function
     (1⊃nr)←header

 :End

 :If (inter←⎕FX nr)≢(fn_name~' ')
    ⍝ Failure
     'Not Able to Fix ',fn_name,' at line: ',⍕inter
 :Else
    ⍝ Success
     'Function Sorted: ',fn_name
 :EndIf


My question is: How do we sort the headers of the methods in a Class ?

Thanks in advance,

Pierre Gilbert
DanB|Dyalog

Re: How to Sort the Headers of the Methods ?

Post by DanB|Dyalog »

User command ]reordLocals will do that for you.
In 12 or 11 you'll have to use Spice to get at it since UCMD don't exist in those versions.
]?reordlocals for details
User avatar
PGilbert
Posts: 440
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to Sort the Headers of the Methods ?

Post by PGilbert »

Thanks Daniel, for functions ]reordlocals worked, thank you. But for a class does not seem to work (I have no return message that it has done something and looking back at the class it has done nothing). Anything special I should know about using this user command with a class ?

Pierre Gilbert
DanB|Dyalog

Re: How to Sort the Headers of the Methods ?

Post by DanB|Dyalog »

You are correct, the 12.1 version only works on fns and ops.
I will see if that can be done for scripted nss/classes. Probably not before the conference tho.
ArrayMac
Posts: 2
Joined: Wed Sep 02, 2009 1:00 am
Contact:

Re: How to Sort the Headers of the Methods ?

Post by ArrayMac »

On a more fundamental level...

Alphabetizing is trivial if one can transform a class/namespace into a character list, an inverse []fx if you will. Does such a function exist? Only working with the texts of :Namespace's and :Class'es via []ed seems to be a crippling limitation.
User avatar
AndyS|Dyalog
Posts: 263
Joined: Tue May 12, 2009 6:06 pm

Re: How to Sort the Headers of the Methods ?

Post by AndyS|Dyalog »

I think that ⎕src and its inverse ⎕fix are what you're looking for. )ed and the keystroke Shift-Enter or the UNIX equivalent are other options rather than ⎕ed

[updated 2010-12-03] Sorry about that .. the cut and paste looked good where I did it from !
Post Reply