Raul wrote:
> sam=: ''1 :(0 :0-.LF)
>   (({. + {: * i.@(>.@((1&{ - {.) % {:))) ,
>    1&{)@(3&{.@(({.~ (# + _3&*@(1: = #))) ,
>     %&100@(-~/@(_2&{.))))
>
>   :([EMAIL PROTECTED] ([EMAIL PROTECTED] + ((1&[EMAIL PROTECTED] - [EMAIL 
> PROTECTED]) % [) *
>    i.@(1: + [)) (>@(2&>@#) |. 2&{.)@])
> )

Brian responded:
>  What a clever approach to cleaning up the code:
>  using an adverb definition for a noun. Great!

I agree.  In fact, I may start using this style to write my long tacit
definitions, instead struggling with  f.  and local vs global definitions
and trying to select meaningful names for subfunctional units of my
definitions....

To that end, I just coded up a little adverb which extends this idea:

         Xn =: 1 : 'u 1 : (; <@:('' '' ,~ }:^:(''NB.'' -: 3 {.&> {:)&.;:);._2
(0 :0))'

It's a little bit like Perl's  /x  regex modifier: it lets you break out
long definitions into readable chunks by inserting whitespace and comments:

           avg =: 'arithmetic mean' Xn
             +/  NB. Sum
         
             %   NB.  J's symbol for division
        
             #   NB.  Tally: number of numbers.
        )
           
           avg
        +/ % #

The adverb is only intended to produce tacit constructs, but since it
employs  :  you could it won't stop you from going explicit.  However, if
that's what you want, you should use  n : 0  directly.  OTOH, there is a
middle ground:

           slice =: ' ' Xn
             NB.  Cut up a list based on the fret provided.
             NB.  (there are better ways to do this, I'm just demonstrating  Xn 
 )
        
                   (<;._2~ u&=)          NB.  cut cleaned list
             @:                    
                   (#~ ([: -. (2#u)&E.)) NB.  remove redundant frets
             @:
                   (,&u^:(~:&u@:{:))     NB.  make sure list ends with fret (for
;._2 )
        )
           
           slice
        (<;._2~ ' '&=)@:(#~ ([: -. '  '&E.))@:(,&' '^:(~:&' '@:{:))

-Dan
-- 
View this message in context: 
http://www.nabble.com/Comments-and-Documentation-tf4873553s24193.html#a14014179
Sent from the J Programming mailing list archive at Nabble.com.

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to