Syntax simplification

This topic is specifically for discussions on the new APL64 Project currently in development. This topic is open for all to browse. However, to post, one must have a registered account on the APLDN forum only available to APL+Win licensee under a current APL+Win Subscription.

Moderators: Tech Support, phpbb_admin

Syntax simplification

Postby Ajay Askoolum » November 3rd, 2018, 6:29 am

- Negative numbers cannot be used for indexing i.e. selecting individual elements.
- To pick, say, the last three columns of a 2D array, you need to explicitlt specify the number of rows.
Code: Select all
      a←2 5⍴⍳10
      2 ¯3↑a
 3 4  5
 8 9 10
Why not simplify the syntax? E.g.
Code: Select all
      a[;¯3] ⍝ synonymous shorter code for 2 ¯3↑a
The payoff of this simplification is material when dealing with multi-dimensional arrays.

Will need to apply to negative row indexing also.
Will need to cope with scenarios where individual rows or columns are also specified.
Ajay Askoolum
 
Posts: 743
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Syntax simplification

Postby Davin Church » November 3rd, 2018, 11:54 am

I see an inconsistency in your suggestion. The ¯3 in your subscripting example needs to specify a single column number but your "equivalent" ↑ specifies 3 columns. Did you mean that the ↑ needed extra code to limit it to a single column?

Also, have you considered using ¯3↑[2] for the purpose of getting the last three columns?
Davin Church
 
Posts: 543
Joined: February 24th, 2007, 1:46 am

Re: Syntax simplification

Postby Ajay Askoolum » November 3rd, 2018, 1:25 pm

Not with you in your first paragraph.
Code: Select all
      a[;¯3]
means the last three columns or 3 columns right to left Am I still missing something, here?

I like ¯3↑[2]; never thought of using ↑ that way. Thanks - it is useful in other ways too.
Code: Select all
      a←3 4⍴12?100
      a
 76 37  6 79
 55 90 99 38
 13 11 19 17
      ((∊2∣¯1↑[2]a)/∊¯1↑[2]a)←¯1
      a
 76 37  6 ¯1
 55 90 99 38
 13 11 19 ¯1
Ajay Askoolum
 
Posts: 743
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Syntax simplification

Postby Davin Church » November 3rd, 2018, 5:08 pm

Ajay Askoolum wrote:Not with you in your first paragraph.
Code: Select all
      a[;¯3]
means the last three columns or 3 columns right to left Am I still missing something, here?

Yes, you cannot use subscripting to mean that. The basis of subscripting requires a specific shape of indexes to produce a specific shape of result. To return the last 3 columns in reverse order you will need to have a three-item subscript, such as:
Code: Select all
a[;¯1 ¯2 ¯3]
or:
Code: Select all
a[;-⍳3]

You may do the same thing with current APL subscripts:
Code: Select all
a[;3↑⌽⍳2⊃⍴a]
or:
Code: Select all
(⌽a)[;⍳3]

or with Take:
Code: Select all
⌽¯3↑[2]a
or:
Code: Select all
3↑[2]⌽a

...any of which are not substantially longer or more difficult to code.
Davin Church
 
Posts: 543
Joined: February 24th, 2007, 1:46 am

Re: Syntax simplification

Postby Ajay Askoolum » November 3rd, 2018, 7:15 pm

Code: Select all
...any of which are not substantially longer or more difficult to code.
Agreed.

My thinking is as follows:

1. Indexing requires positive integers.
2. The semi-colon imparts meaning to which plane the indexing applies. For a 2-D array, if the index follows the semi-colon, it applies on the y- or vertical- axis

Therefore if the index is negative, it is not conforming to the above. The interpreter can take that to mean it needs to do something else.

a[;¯3] simply means the last three columns; hence the suggestion.

Rotating the array and selecting the first column does not quite work for arrays with rank higher than 2 when a single column is selected.
Code: Select all
      a←4 3 5⍴⍳1000
      a[;;5]
  5 10 15
 20 25 30
 35 40 45
 50 55 60
      1↑[3](⌽a)
  5
 10
 15

 20
 25
 30

 35
 40
 45

 50
 55
 60
It does when multiple columns are selected as long as you remember to rotate the result
Code: Select all
     a[;;3 4 5]
  3  4  5
  8  9 10
 13 14 15

 18 19 20
 23 24 25
 28 29 30

 33 34 35
 38 39 40
 43 44 45

 48 49 50
 53 54 55
 58 59 60
      ⌽3↑[3](⌽a)
  3  4  5
  8  9 10
 13 14 15

 18 19 20
 23 24 25
 28 29 30

 33 34 35
 38 39 40
 43 44 45

 48 49 50
 53 54 55
 58 59 60
I think what I suggested is a more intuitive syntax (if it were to work)
Code: Select all
     a[;;¯3]
Ajay Askoolum
 
Posts: 743
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Syntax simplification

Postby Davin Church » November 3rd, 2018, 10:15 pm

I disagree, simply because the structure of the code doesn't fit that. APL should do the same thing, structurally, regardless of the values of the subscripts. You may create a new syntax/function by which it does a take-like operation, or you may cause negative numbers to do something slightly different than positive numbers, but to keep APL consistent the shape of the subscripts and results must remain compatible with the current system. The definition of that structure (for a 3-D example) is:
Code: Select all
⍴X[A;B;C]  ←→  (⍴A),(⍴B),⍴C

You can't really change that identity and still have APL.
Davin Church
 
Posts: 543
Joined: February 24th, 2007, 1:46 am

Re: Syntax simplification

Postby Ajay Askoolum » November 4th, 2018, 3:56 am

I do not see why given
Code: Select all
      a←4 3 5⍴⍳1000, a[;;¯3] cannot be implemented such that it matches 4 3 ¯3↑a
The syntax is
- supplementary to the existing syntax i.e. does not change anything that exists
- does not introduce any ambiguity.
- is a shorter form and eliminates hard coding (of the dimensions).
Ajay Askoolum
 
Posts: 743
Joined: February 22nd, 2007, 2:16 am
Location: United Kingdom

Re: Syntax simplification

Postby Davin Church » November 4th, 2018, 10:59 am

As noted above, it DOES change the existing syntax (size equivalences) and it DOES introduce ambiguity (i.e. what does DATA[;X] return?).
Davin Church
 
Posts: 543
Joined: February 24th, 2007, 1:46 am


Return to APL64 Project

Who is online

Users browsing this forum: No registered users and 1 guest

cron