Pascal, Your suggestions helped me understand this problem:

 

   pairs=: 13 :'(>:@i. x),"0/>:@i. y'

   cb=: 13 :'<"0 >:@i. y'

   cb

[: <"0 >:@i.

   count=: 13 :'(<@cb)"1 x pairs y'

   2 count 2

┌───┬─────┐
│┌─┐│┌─┬─┐│
││1│││1│2││
│└─┘│└─┴─┘│
├───┼─────┤
│┌─┐│┌─┬─┐│
││1│││1│2││
│├─┤│├─┼─┤│
││2│││3│4││
│└─┘│└─┴─┘│
└───┴─────┘

   count2=: 13 :'(<@<"0 >:@i. y)"1 x pairs y'

   2 count2 2

┌───┬───┐
│┌─┐│┌─┐│
││1│││2││
│└─┘│└─┘│
├───┼───┤
│┌─┐│┌─┐│
││1│││2││
│└─┘│└─┘│
└───┴───┘

┌───┬───┐
│┌─┐│┌─┐│
││1│││2││
│└─┘│└─┘│
├───┼───┤
│┌─┐│┌─┐│
││1│││2││
│└─┘│└─┘│
└───┴───┘

   count3=: 13 :'<@([: <"0 >:@i.)"1 x pairs y'

   2 count3 2

┌───┬─────┐
│┌─┐│┌─┬─┐│
││1│││1│2││
│└─┘│└─┴─┘│
├───┼─────┤
│┌─┐│┌─┬─┐│
││1│││1│2││
│├─┤│├─┼─┤│
││2│││3│4││
│└─┘│└─┴─┘│
└───┴─────┘

   (2 count 2)-:2 count3 2

1

   count 

[: <@cb"1 pairs

   count3

[: <@([: <"0 >:@i.)"1 pairs

   

   count4=: 13 :'([:<([: <"0 [:>:i.))"1 x pairs y'

   2 count4 2

┌───┬─────┐
│┌─┐│┌─┬─┐│
││1│││1│2││
│└─┘│└─┴─┘│
├───┼─────┤
│┌─┐│┌─┬─┐│
││1│││1│2││
│├─┤│├─┼─┤│
││2│││3│4││
│└─┘│└─┴─┘│
└───┴─────┘

   (2 count3 2)-:2 count4 2

1

   

   cb

[: <"0 >:@i.

   count

[: <@cb"1 pairs

   count3

[: <@([: <"0 >:@i.)"1 pairs

   count4

[: ([: < [: <"0 [: >: i.)"1 pairs

 

Is there a general preference among programmers for count3 or count4

  

   5!:4 <'count3'

  ┌─ [:                        
  │             ┌─ <           
  │             │   ┌─ [:      
  │       ┌─ @ ─┤   │     ┌─ < 
  │       │     │   ├─ " ─┴─ 0 
──┤       │     └───┤          
  ├─ " ───┤         │     ┌─ >:
  │       │         └─ @ ─┴─ i.
  │       └─ 1                 
  └─ pairs                     

   5!:4 <'count4'

  ┌─ [:                       
  │           ┌─ [:           
  │           ├─ <            
  │           │    ┌─ [:      
  │       ┌───┤    │     ┌─ < 
  │       │   │    ├─ " ─┴─ 0 
──┤       │   └────┤          
  ├─ " ───┤        │     ┌─ [:
  │       │        └─────┼─ >:
  │       │              └─ i.
  │       └─ 1                
  └─ pairs                    

 

Linda  

                                

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of 'Pascal Jasmin' 
via Programming
Sent: Thursday, February 12, 2015 9:13 AM
To: [email protected]
Subject: Re: [Jprogramming] Source of frustration

 

 

 

([: v [: u ]) is almost but not exactly the same as

 

([: v@:u ])

 

basically, if u has any adverbs applied to it (such as "1) then those adverbs 
also apply to v in v@:u.  But don't apply to v in ([: v u)

 

A good reason for 13 : to have given you what you got is that you explicitly 
used @ instead of made just a linear phrase.  

 

 

 

 

________________________________

From: Linda Alvord < <mailto:[email protected]> [email protected]>

To:  <mailto:[email protected]> [email protected] 

Sent: Thursday, February 12, 2015 3:09 AM

Subject: Re: [Jprogramming] Source of frustration

 

 

There have been many explanations of y=how @ works, but here is the question

I really am interested in.

 

Working code:

  (i.4)*/>:i.5

1 2  3  4  5

2 4  6  8 10

3 6  9 12 15

4 8 12 16 20

Simple working definition:

  times=: 13 :'(>:i.x)*/>:i.y'

   4 times 5

1 2  3  4  5

2 4  6  8 10

3 6  9 12 15

4 8 12 16 20

Definition which also works but  seems cumbersome:  

   times2=: 13 :'(>:@i.x)*/>:@i.y'

   4 times 5

1 2  3  4  5

2 4  6  8 10

3 6  9 12 15

4 8 12 16 20

Why couldn't my definition of times be converted to what seems to be the

preferred J version in times2?  

   times 

([: >: [: i. [) */ [: >: [: i. ]

  

   times2

([: >:@i. [) */ [: >:@i. ]

 

Linda

  

-----Original Message-----

From:  <mailto:[email protected]> 
[email protected]

[ <mailto:[email protected]> 
mailto:[email protected]] On Behalf Of Linda Alvord

Sent: Monday, February 9, 2015 5:01 PM

To:  <mailto:[email protected]> [email protected]

Subject: Re: [Jprogramming] Source of frustration

 

Here's another example of my suggestion:

 

 

 

These two expressions have the same result.

 

 

 

           eb=: 13 :'y $<'' '''

 

   ([:<eb)"1(>:i.2),"0/>:i.4

 

----T-----T-------T---------┐

│--┐│--T-┐│--T-T-┐│--T-T-T-┐│

││ │││ │ │││ │ │ │││ │ │ │ ││

│L--│L-+--│L-+-+--│L-+-+-+--│

+---+-----+-------+---------+

│--┐│--T-┐│--T-T-┐│--T-T-T-┐│

││ │││ │ │││ │ │ │││ │ │ │ ││

│+-+│+-+-+│+-+-+-+│+-+-+-+-+│

││ │││ │ │││ │ │ │││ │ │ │ ││

│L--│L-+--│L-+-+--│L-+-+-+--│

L---+-----+-------+----------

 

   ([:<eb)"1(>:i.2),"0/>:i.4

 

----T-----T-------T---------┐

│--┐│--T-┐│--T-T-┐│--T-T-T-┐│

││ │││ │ │││ │ │ │││ │ │ │ ││

│L--│L-+--│L-+-+--│L-+-+-+--│

+---+-----+-------+---------+

│--┐│--T-┐│--T-T-┐│--T-T-T-┐│

││ │││ │ │││ │ │ │││ │ │ │ ││

│+-+│+-+-+│+-+-+-+│+-+-+-+-+│

││ │││ │ │││ │ │ │││ │ │ │ ││

│L--│L-+--│L-+-+--│L-+-+-+--│ L---+-----+-------+----------

 

 

 

Define each one as  I  and  j

 

 

 

  

 

   i=: 13 :'(<@eb)"1(>:@i.x),"0/>:@i.y'

 

   j=: 13 :'([:<eb)"1(>:i.x),"0/>:i.y'

 

 

 

Both agree as monads and dyads.  

 

 

 

(i 2)-:j 2

 

1

 

   (2 i 4)-:2 j 4

 

1

 

In the interpretation of J,  [:  is inserted when appropriate.

 

 

 

My question is: "why couldn't both have the same

 

Definition when trains are involved. It @ is superior, I would suggest the

definition of  i

 

for both.  

 

  

 

    eb

 

(<' ') $~ ]

 

  

 

   i

 

[: <@eb"1 ([: >:@i. [) ,"0/ [: >:@i. ]

 

  

 

   j

 

[: ([: < eb)"1 ([: >: [: i. [) ,"0/ [: >: [: i. ]

 

 

 

Linda

 

  

 

   eb  

 

(<' ') $~ ]

 

  

 

 

 

-----Original Message-----

From:  <mailto:[email protected]> 
[email protected]

[ <mailto:[email protected]> 
mailto:[email protected]] On Behalf Of Kip Murray

Sent: Monday, February 9, 2015 11:00 AM

To:  <mailto:[email protected]> [email protected]

Subject: Re: [Jprogramming] Source of frustration

 

 

 

And this:

 

 

 

   hh =: 3 : '[: >: i. y'

 

   hh

 

3 : '[: >: i. y'

 

   hh 4

 

|domain error: hh

 

|       [:>:i.y

 

 

 

I think Brian's suggestion that you parenthesize the result of 13 : before

applying arguments is the best way of removing your frustration.  My point

about parenthsizing [: > i. before applying arguments is specific to verbs

defined by trains.

 

 

 

--Kip

 

 

 

 

 

On Monday, February 9, 2015, Linda Alvord < < <mailto:[email protected]> 
mailto:[email protected]>

 <mailto:[email protected]> [email protected]> wrote:

 

 

 

> How about this:

 

> h=: 13 :'[:>:i.y'

 

>    h

 

> [: [: [: >: i.

 

> 

 

>    [: [: [: >: i. 4

 

> |domain error: scriptd

 

> |   [:[:    [:>:i.4

 

> 

 

> Linda

 

> 

 

> 

 

> -----Original Message-----

 

> From:  < <mailto:[email protected]> 
> mailto:[email protected]>

 <mailto:[email protected]> 
[email protected] <javascript:;> 

 

> [ 

> < <mailto:[email protected]%20%3cjavascript:;%3e> 
> mailto:[email protected]%20%3cjavascript:;%3e>

 <mailto:[email protected]> 
mailto:[email protected] <javascript:;>] On 

 

> Behalf Of Brian Schott

 

> Sent: Monday, February 9, 2015 10:00 AM

 

> To: Programming forum

 

> Subject: Re: [Jprogramming] Source of frustration

 

> 

 

> Linda,

 

> 

 

> If you are willing to put parentheses around your example verbs --

 

> with the data outside the parens, you will not get the domain error.

 

> 

 

> On Mon, Feb 9, 2015 at 9:54 AM, Linda Alvord <[email protected]

 

> <javascript:;>>

 

> wrote:

 

> 

 

> > Suppose:   ff=: 13 :'>:i.y'

 

> >    ff

 

> > >:@i.

 

> > Then:

 

> >   >:@i.4

 

> > 1 2 3 4

 

> > Which is what you want, more than a domain error.

 

> >

 

> > Linda

 

> >

 

> > --

 

> (B=)

 

> ----------------------------------------------------------------------

 

> For information about J forums see  

> < <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm>

 <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm

 

> 

 

> ----------------------------------------------------------------------

 

> For information about J forums see  

> < <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm>

 <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm

 

> 

 

 

 

 

 

--

 

Sent from Gmail Mobile

 

 

 

 

----------------------------------------------------------------------

 

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

 <http://www.jsoftware.com/forums.htm> http://www.jsoftware.com/forums.htm

 

----------------------------------------------------------------------

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

 

----------------------------------------------------------------------

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

----------------------------------------------------------------------

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

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

Reply via email to