I put this in the earlier thread also:

    ]A=:0 1 1
0 1 1
   ]B=:i.2 3 2
 0  1
 2  3
 4  5

 6  7
 8  9
10 11
   
   _1|. 1{ ($B)$2|.,B
 0  1
 8  9
10 11
   
   f=: 13 :' _1|. 1{ ($y)$2|.,y'
   
   f B
 0  1
 8  9
10 11
   
   f
_1 |. 1 { $ $ 2 |. ,


I can't decide if you have to get the desired result using all the data or if 
just getting there is ok.  It probably depends on the nature of the problem and 
how general a result you are looking for rather than a whole category of 
similar problems.

Linda
   

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of 'Pascal Jasmin' 
via Programming
Sent: Monday, July 21, 2014 11:13 PM
To: [email protected]
Subject: Re: [Jprogramming] filtermod and currying


An improved version of filtermod.  The conjunction uses v to select and u to 
modify the selection.

itemamend =: (([: ;/(,.i.@#))@:[ { ])"1 _
filtermod =: 2 : 'v itemamend ] ,: v # inv [: u v # ]' 

an adverb version just uses x as the modified replacement for the selection

filtermodA =: 1 : 'u itemamend ] ,:  (#inv~ u)'

   (3;4;0$0) (a: = ]) filtermodA a: ,~ a: ,~ a:, 1 ;2 
┌─┬─┬─┬─┬┐ 
│3│1│2│4││ 
└─┴─┴─┴─┴┘ 
above replaces empty boxes in y, but leaves one empty.

currying in J is typically thought of as bond &, but that can only bond an 
entire x or y.  The above filling of boxes can let us build the input to 
functions that parse multiple parameters from x or y.

A curry verb to start

curry =: 4 : '(boxopen y) (a: = ]) filtermodA x' 

   (( 3$ a: ) curry a:, 1;a:) curry 3;2 
┌─┬─┬─┐ 
│3│1│2│ 
└─┴─┴─┘ 
   (( 3$ a: ) curry a:, 1;a:) curry 3;a: 

┌─┬─┬┐ 
│3│1││ 
└─┴─┴┘ 

There is 2 calls to curry each filling in parameters, and in the second 
example, the result still includes missing parameters.

A curry conjunction is used to bind partially filled parameters to a verb, 
which can be called with the missing parameters:


curryB=: 2 : 'u@:(n&curry)'

  (3 :'l*w*h [''l w h'' =. y') curryB ((( 3$ a: ) curry a:, 1;a:) curry 3;a:)
3 : 'l*w*h [''l w h'' =. y'@:((3;1;0$0) (1 : '(boxopen y) (a: = ]) filtermodA 
m'))

function on the left is volume that takes 3 parameters.  The result of the 
conjunction has bound 2 of the 3 parameters to 3;1

   (3 :'l*w*h [''l w h'' =. y')curryB((( 3$ a: ) curry a:, 1;a:) curry 3;a:) 4 
12 
   ; curryB ((( 3$ a: ) curry a:, 1;a:) curry 3;a:) 4 
3 1 4 

parameters can be bound in arbitrary positions, and works with gerunds or other 
code fragments, so is likely more flexible than other languages.


________________________________
From: Pascal Jasmin <[email protected]>
To: "[email protected]" <[email protected]> 
Sent: Saturday, July 12, 2014 1:16:59 AM
Subject: Re: [Jprogramming] speaking of amend... filtermod a useful    
conjunction


missing isNoun

isNoun =: (0 = 4!:0 ( :: 0:))@:<  





----- Original Message -----
From: 'Pascal Jasmin' via Programming <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Saturday, July 12, 2014 12:16:24 AM
Subject: Re: [Jprogramming] speaking of amend... filtermod a useful    
conjunction



before implementing Kip's version, here is a useful though hacky conjunction I 
call filtermod.
The v side produces a filter (list of 1s and 0s), the u side takes as argument 
the list selected by the filter and just needs to return the same number of 
items.  It may modify and even reorder the items.  After u is done, the new 
items in new order will be inserted back into the list at the filtered indexes.

filtermod =: 2 : 0 NB. v is filter func, u is func that modifies items.  then 
modified items replaced in original. 
if. isNoun 'u' do. '`box mod' =. u else. '`box mod' =. ]`u end. 
a =. v y 
> a} box y,:   a # inv mod a # y 
: 
if. isNoun 'u' do. '`box mod' =. u else. '`box mod' =. ]`u end. 
a =. x v y 
> a}  box y,:   a # inv x mod a # y 
)

u can optionally be a gerund, though its a bit hacky, it may be more flexible 
than Kip's solution.  The typical gerund addition would be <"1, but it can be 
any verb necessary to provide amend with a conforming shape.


for rows that total over 6, slide the tail element into the next pair:

   <"1`({."1,. _1 |. {:"1) filtermod ((6 < +/"1)) i. 6 2 
 0  1 
 2  3 
 4 11 
 6  5 
 8  7 
10  9 

simpler ones:

   2 (5&+) filtermod  < i. 6 
NB. ^: trick
0 1 2 13 14 15 
   2 (5 + ]) filtermod  < i. 6  NB. add 5 to items greater than 2
0 1 2 8 9 10 

   2 (2|. 5 + ]) filtermod  < i. 6 NB. and reordered.
0 1 2 10 8 9 




----- Original Message -----
From: Kip Murray <[email protected]>
To: "[email protected]" <[email protected]>
Cc: 
Sent: Friday, July 11, 2014 11:09:10 PM
Subject: Re: [Jprogramming] speaking of amend...

   v =: (-. , ])@[ # ,/@]
   0 1 1 v i. 2 3 2
0  1
8  9
10 11

On Friday, July 11, 2014, Linda Alvord <[email protected]> wrote:

> I made it too hard because I thought I had seen carriage returns.
>
>     f=: 13 :'(x}i.2 3){((*/0 1{$y),2)$,y'
>    f
> 4 : '(x}i.2 3){((*/0 1{$y),2)$,y'
>    0 1 1 f i.2 3 2
>  0  1
>  8  9
> 10 11
>
> Linda
>
> -----Original Message-----
> From: [email protected] <javascript:;>
> [mailto:[email protected] <javascript:;>] On
> Behalf Of Linda Alvord
> Sent: Friday, July 11, 2014 10:53 PM
> To: [email protected] <javascript:;>
> Subject: Re: [Jprogramming] speaking of amend...
>
>  I'm sure I'll learn lots of better ways than this.
>
>  f=: 13 :'3 1 2$,(x}i.2 3){((*/0 1{$y),2)$,y'
>    f
> 4 : '3 1 2$,(x}i.2 3){((*/0 1{$y),2)$,y'
>
>    0 1 1 f i.2 3 2
>  0  1
>
>  8  9
>
> 10 11
>
> Linda
>
> -----Original Message-----
> From: [email protected] <javascript:;>
> [mailto:[email protected] <javascript:;>] On
> Behalf Of 'Pascal
> Jasmin' via Programming
> Sent: Friday, July 11, 2014 8:57 PM
> To: Programming forum
> Subject: [Jprogramming] speaking of amend...
>
> what verb v (or I guess adverb is ok) could I use to get
>
> 0 1 1 v i. 2 3 2
>
> 0  1
> 8  9
> 10 11
>
>
>     i.2 3 2
>  0  1
>  2  3
>  4  5
>  6  7
>  8  9
> 10 11
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


-- 
Sent from Gmail Mobile






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

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

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

Reply via email to