Good example of pattern programming

[spoiler]










>From first sight it seems unfit, but |. indeed fixes
it nicely. For u`v/ rolling result is needed.


First I got a direct result

   (3 (-~ ,~ [) 5) p. (i.@>:%]) 10
3 3.2 3.4 3.6 3.8 4 4.2 4.4 4.6 4.8 5

made it tacit with multiple arguments

   ((],-)~/@}: p. (i.@>:%])@{:)  3 5 10
3 3.2 3.4 3.6 3.8 4 4.2 4.4 4.6 4.8 5

and then fitted into the u`v/ pattern:

   (p. i.@>: % ])~`(],-)/@|.     3 5 10
3 3.2 3.4 3.6 3.8 4 4.2 4.4 4.6 4.8 5

> From: Raul Miller <[EMAIL PROTECTED]>
>
> If I wanted to make steps be more concise I would probably use
> steps =: {. - -/@}: * (i.@>: % ])@{:
> 
> Anyways, I don't see much room for improvement, there.


> From: Brian Schott <[EMAIL PROTECTED]>
> 
>     Ok, "steps" is an awkward match, but I believe it
> can be forced into u`v/ gerund (almost).
> 
> 
>    stps =: ([EMAIL PROTECTED]:@[*i.@>:@] % {:@])~`(],-)/@|.

> From: Brian Schott <[EMAIL PROTECTED]>
> 
>     What about expanding it to another widely used
> verb, steps?
> 
>    steps =: {. + (1&{ - {.) * (i.@>: % ])@{:
>    steps 3 5 10
> 3 3.2 3.4 3.6 3.8 4 4.2 4.4 4.6 4.8 5


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

Reply via email to