How to Sort the Headers of the Methods ?

Writing and using Classes in Dyalog APL

How to Sort the Headers of the Methods ?

Postby PGilbert on Mon Aug 30, 2010 1:30 pm

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
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to Sort the Headers of the Methods ?

Postby DanB|Dyalog on Mon Aug 30, 2010 6:31 pm

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
DanB|Dyalog
 

Re: How to Sort the Headers of the Methods ?

Postby PGilbert on Mon Aug 30, 2010 7:02 pm

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
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to Sort the Headers of the Methods ?

Postby DanB|Dyalog on Tue Aug 31, 2010 5:22 pm

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.
DanB|Dyalog
 

Re: How to Sort the Headers of the Methods ?

Postby ArrayMac on Tue Nov 30, 2010 4:26 pm

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.
ArrayMac
 
Posts: 2
Joined: Wed Sep 02, 2009 1:00 am

Re: How to Sort the Headers of the Methods ?

Postby AndyS|Dyalog on Tue Nov 30, 2010 8:40 pm

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 !
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm


Return to Object Oriented Programming

Who is online

Users browsing this forum: No registered users and 1 guest