Newsgroups: comp.lang.apl
Path: watmath!watserv1!utgpu!news-server.csri.toronto.edu!rpi!gatech!gsusgi1.gsu.edu!gsusgi1.gsu.edu!qmdbms
From: qmdbms@gsusgi2.gsu.edu (Brian Schott)
Subject: Re: Is hook special
Message-ID: <qmdbms.705836966@gsusgi1.gsu.edu>
Organization: Georgia State University
References: <qmdbms.705703600@gsusgi1.gsu.edu> <ROCKWELL.92May12192510@socrates.umd.edu>
Date: Thu, 14 May 1992 09:49:26 GMT
Lines: 54

rockwell@socrates.umd.edu (Raul Deluth Miller-Rockwell) writes:

>Brian Schott:
>   The following J session suggests that a fork cannot be used as the
>   verb in an "amend" construction.  Have I drawn the wrong
>   conclusion?

>Yes.  In fact, your session first successfully uses a fork with the
>      u =. 2&{"1@i      NB. extract column 2 of indices
>      a =. 5&<@(2&{"1)  NB. select elements in column 2 > 5
>      w =. 5 3 $1 7 4 5 2 0 6 6 9 3 5 8 0 0 5   NB. random array
>      <:@(a@]#u@])  w   NB. checking indices to be used by "ammend"
>   7 10
>      200 <:@(a@]#u@]) } w      NB. do it
>   1   7 4
>   5   2 0
>   6 200 9
>   3 200 8
>   0   0 5

>      <:@(a#u) w                NB. try same as above with "a fork"
>   7 10
>      200 <:@(a#u)} w           NB. but now "domain error"
>   domain error


Looking again at your suggestions and having gotten some help from Gene
Mcdonnel (sp?, sorry), I am beginning to understand the situation a
little better.  I apparently couldn't even see the '@]' suffixed onto
several verbs (e.g. i.@$@]   a@]#u@]  ) !!! I am not quite clear yet,
                        ^^    ^^  ^^
though.

I have had a difficult time imagining the need for this suffix; I thought
it was a do-nothing addon, especially for a monadic verb. It appears to be
preserving some needed rank consistency in the sequence of verbs, but I
cannot see exactly why. Maybe someone can explain?

>Another approach might be to reformulate your expression so it
>operates on vectors:
>   ammend =. #&1 @(5&<) @(2&{) @] } "1
>   200 ammend w
>[same result as above]

The snippit above is very helpful.  It not only shows the elegance and
efficiency of operating on vectors, but it has a hidden pearl for me:
the prefix '#&1' is apparently a trick to preserve rank, also.  In this
case, does it force its input to become a vector, instead of a scalar,
because the rank of "tally" '#' is (1 _)?
-- 
Brian Schott/Decision Sciences Dept.             qmdbms@gsusgi2.gsu.edu
College of Business Administration                         404-651-4070
Georgia State University                  interests: approx. reasoning,
Atlanta, Georgia USA 30303-3083     (B=)       decision support systems
