simlified amendments 
Author Message
 simlified amendments

This remark is in line with the frequently discussed `problems' with
the amend syntax.  It was often stated that amending an array is
awkward in J.  In particular, it was lamented that one does not have
the flexibility of the APL syntax of brackets.  One approach to allow
direct amendements of cells suggested by Sam Sirlin uses this
devious verb:


in this construction

        x  (cell;cell;cell...) inx y } y .

To avoid two appearances of y I have suggested the adverb:


So I write

        x  (cell;cell;cell...) am y
instead.

It leaves the mechanics of cells specifications up to me.  I
can do quite a bit with this, in fact any amendment.  But it appears
that in practice it requires specifying the y again in this process.
Thus, the adverb leaves something to be desired.  

But in addition to this it is not easy memorize, and it does not come
naturally.  Here is a simple alternative which appears to be quite
versatile.

Write


        INS=.(&{) ins  .


adverbs.  The argument for each train is a verb or a noun (on the left) which
altogether creates a series of verbs like a domino.  INS will
accept the syntax of am and some other types of cell specifications
which are inherited from { not available to am.  But I can't use ranks
and perhaps other selections from the array of indices of elements of
y.  Thus, ins is much more useful.

Suppose

        a=.i. 3 4

Then I can say:

   _10 1 (0 0; 2 3) INS a
_10 1  2 3
  4 5  6 7
  8 9 10 1

and
   (?2 4$100)   0 1 INS a
13 75 45 53
21  4 67 67
 8  9 10 11

By opting for ins  I can say instead

   _10 1 (0 0; 2 3)&{ ins a
   (?2 4$100)   0 1&{ ins a

But I can also amend a col and the main diagonal for example:

   10 20 30 (0&{"1) ins a
10 1  2  3
20 5  6  7
30 9 10 11

   10 20 30 (<0 1)&|: ins a  
10  1  2  3
 4 20  6  7
 8  9 30 11

In fact, whatever facilities J provides for selections from the indices: i.$ y
are available this way.  It means that my comfort with } depends on my
comfort with the rest of J.  In particular, I think of { as a kin of } .
Thus I can amend all the cells expressible via { .  For example:

Because:
   (<(<<1), (<<1 2))&{ i.$ a
0  3
8 11

I can say:
    (- 2 2$1 10 100 1000)(<(<<1), (<<1 2))&{ ins a
  _1 1  2   _10
   4 5  6     7
_100 9 10 _1000

to amend the `corners'.  I can't be too wild because conformity with
the shapes given in the definition of } should be kept.  The main
disadvantage of using INS or ins is that i. $ is performed on any y.
This can be expensive.  How crucial it is depends on the size of y.
Personally, I have not found it a real issue.

Eythan

PS:  For simple column and row amendments I work directly with } using
idioms in a manner shown a long time ago by Raul Rockwell:

   (_1 _2)2 3}"1 a
0 1 _1 _2
4 5 _1 _2
8 9 _1 _2

      (3 2 $_1 _2 _3 _4 _5 _6)2 3}"1 a
0 1 _1 _2
4 5 _3 _4
8 9 _5 _6

    (_1 _2)2 0}"1&.|: a
_2 _2 _2 _2
 4  5  6  7
_1 _1 _1 _1



Sun, 21 Jan 1996 02:43:20 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. From/Amendment in J2.03

2. File Loaded Drop Combo -Tip Amendment article 14361

3. DC. Amendment to job description

4. IBM and reaffirmation of the current ANSI COBOL Standard and Amendments

5. Reaffirmation - JUST the Correction Amendment

6. Reaffirmation of the current ANSI COBOL Standard (and its two amendments)

7. Suggested amendment to PEP 255 (fwd)

 

 
Powered by phpBB® Forum Software