[comp.lang.apl] J questions

cs450a03@uc780.umd.edu (04/03/91)

Ethan Weg writes:
>1) Let us define a conjunction say t=.2 :  ' x. y.'.
>   Suppose I do +/ t 1 2.  The answer is 3.  Now suppose a=.2 2 $1 2 3 4.
>   I want t to operate on the cells of rank 1 of a.  I do I use the rank
>   conjunction to obtain the sum of the rows of a?  I want to use t.

I presume you meant "How do I use the rank conjunction..."

Note that t is not a verb, and the result of t is not a verb in this
case.  Still, you could try       +/"1 t a

>2) Is there a way to use J in a filter like cat file|J|awk|J...?

Well, you can set yourself up a profile and make it read from standard
input and write to standard output.  I don't think J has developed far
enough yet that I'd want to set things up this way.  (Yet)

>3) Quite generally can one imagine J acting as a shell?

The flexibility and syntax would be nice, eh?

I think, however, that a lot of the elegance of J results because data
objects are fairly static.  The efficiency is way to low to do
character by character stuff, and adding a "character stream" "type"
to J would be essentially a complete re-write.

I suppose step one in this direction would be an efficient
implementation of J.  (Which probably would mean bypassing C and
working in assembler -- which is painful because it's hard to port).

But just because it's impractical doesn't mean it isn't worth
thought.... 

Raul

weg@convx1.ccit.arizona.edu (Eythan Weg) (04/03/91)

Hi there:
I have a few questions to J-wise people:

1) Let us define a conjunction say t=.2 :  ' x. y.'.
   Suppose I do +/ t 1 2.  The answer is 3.  Now suppose a=.2 2 $1 2 3 4.
   I want t to operate on the cells of rank 1 of a.  I do I use the rank
   conjunction to obtain the sum of the rows of a?  I want to use t.

2) Is there a way to use J in a filter like cat file|J|awk|J...?

3) Quite generally can one imagine J acting as a shell?

Thanks, Eythan

hui@yrloc.ipsa.reuter.COM (Roger Hui) (04/03/91)

1. To find the sum of the rows of matrix a using the conjunction t
that you defined, t=. 2 : 'x. y.', say:  +/"1 t a .

2. J uses only standard-in and standard-out for input and output.

Roger Hui
Iverson Software Inc., 33 Major Street, Toronto, Ontario M5S 2K9
(416) 925 6096

weg@convx1.ccit.arizona.edu (Eythan Weg) (04/04/91)

I will revise my first question:
Let t=.2 : '(x.1{.y.),_1{.y.'.  Now  ^&2 t 2 3 should produce 4 3.
I want to see t as a black box which operates on the right on vectors.
Now how do I deal with a matrix whose rows are supposed to serve as
a series of right operands? How can I force the conjunction to behave
as if it is a verb with a specified right rank?  So if a=.i.4 then 
^&3 t "1 a will give 2 2$0 1 8 3.  My problem is that " works
essentially on verbs.  
Thank you.  Eythan

cs450a03@uc780.umd.edu (04/05/91)

Eythan Weg writes:
>I will revise my first question:
>Let t=.2 : '(x.1{.y.),_1{.y.'.  Now  ^&2 t 2 3 should produce 4 3.
>I want to see t as a black box which operates on the right on vectors.

t =. 2 : '(x.1{."1 y.), _1{."1 y.'

or

t=. 1 : '(x.@{.),_1&{.'

then    ^&2 t   is a verb

Raul Rockwell

cs450a03@uc780.umd.edu (04/05/91)

I wrote:

>t=. 1 : '(x.@{.),_1&{.'


I should have said

t=. 1 : '(x.@(1&{.)) , _1&{.'

oops...

Raul

hui@yrloc.ipsa.reuter.COM (Roger Hui) (04/05/91)

In article <WEG.91Apr3231451@convx1.convx1.ccit.arizona.edu> weg@convx1.ccit.arizona.edu (Eythan Weg) writes:

>I will revise my first question:
>Let t=.2 : '(x.1{.y.),_1{.y.'.  Now  ^&2 t 2 3 should produce 4 3.
>I want to see t as a black box which operates on the right on vectors.
>Now how do I deal with a matrix whose rows are supposed to serve as
>a series of right operands? How can I force the conjunction to behave
>as if it is a verb with a specified right rank?  So if a=.i.4 then 
>^&3 t "1 a will give 2 2$0 1 8 3.  My problem is that " works
>essentially on verbs.  

The rank conjunction " does indeed work only on verb right arguments.
If f is verb, then
  f"0 x    applies f to each rank-0 cell (each scalar) of x
  f"1 x    applies f to each rank-1 cell (each vector) of x
  f"k x    applies f to each rank-k cell of x
(Try  x=.i.2 3 4 5  and  f=.<  or  f=.+/  )

No other conjunction needed.  If you insist on having this conjunction t,
it is for reasons that you have not yet mentioned.

Roger Hui
Iverson Software Inc., 33 Major Street, Toronto, Ontario  M5S 2K9
(416) 925 6096