why?

General APL language issues

why?

Postby askom on Mon May 17, 2010 11:44 pm

x←(1 2 3)(4 2 5)
1∘.,x
1 1 2 3 1 4 2 5
1∘.,[1.5]x
SYNTAX ERROR
1∘.,[1.5]x


Regards,
Sasha.
askom
 
Posts: 36
Joined: Fri Apr 09, 2010 7:22 pm

Re: why?

Postby giangiquario on Tue May 18, 2010 7:26 am

Maybe the correct spelling is
Code: Select all
1∘.(,[1.5])x


Regards, Gianluigi
User avatar
giangiquario
 
Posts: 46
Joined: Thu Nov 26, 2009 8:55 am
Location: Milano, Italia

Re: why?

Postby JohnS|Dyalog on Tue May 18, 2010 8:04 am

Code: Select all
I think Gianluigi is right:

      x←(1 2 3)(4 5 6)

      1∘.,x
 1 1 2 3  1 4 5 6

      1∘.,[1.5]x
SYNTAX ERROR
      1∘.,[1.5]x
     ∧

      1∘.(,[1.5])x
 1 1  1 4
 1 2  1 5
 1 3  1 6

      )copy dfns ddft
u:\ws\dfns saved Sat May 15 11:54:54 2010

      ∘.,[1.5] ddft 1   ⍝ display derived function tree.
    [   
  ┌─┴─┐ 
  .   1.5
┌─┴─┐   
∘   ,   

      ∘.(,[1.5]) ddft 1
  .       
┌─┴─┐     
∘   ,[·1.5

JohnS|Dyalog
 

Re: why?

Postby askom on Tue May 18, 2010 5:22 pm

Thanks Gianluigi and John. It's a pity that it is not a bug.
Not easy to explain to students and not pleasant to look at that code:-)

In APL2 it works like I posted.
askom
 
Posts: 36
Joined: Fri Apr 09, 2010 7:22 pm

Re: why?

Postby Phil Last on Tue May 18, 2010 9:39 pm

Binding strengths.
APL2           Dyalog        
right-operand  vector        
bracket        bracket       
vector         right-operand 
left-operand   left-operand  
left-argument  left-argument 
right-argument right-argument
There are good arguments for either order and both create strange (yes, and ugly) seeming anomolies.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: why?

Postby askom on Tue May 18, 2010 10:44 pm

Good analysis. Thanks.

I vote for the short one:-) APL2.

/Sasha.
askom
 
Posts: 36
Joined: Fri Apr 09, 2010 7:22 pm

Re: why?

Postby askom on Tue May 18, 2010 11:07 pm

look at the expression again:
1∘.,[1.5]x

my way of explanation, right to left movement:
x is a variable, look to the left to see what to do
] may be index or axis specification, go more to the left
, may be ravel or concatenate, go more to the left
. may be inner product or outer product, go more to the left
∘. is the inner product, so "," is the right operand and [1.5] axis spec
1 is the left argument

I always tell to my students that the only use of parentheses is change the order
of execution.
1∘.(,[1.5])x
The above is not change the order of execution. I was wrong:-(
askom
 
Posts: 36
Joined: Fri Apr 09, 2010 7:22 pm

Re: why?

Postby Phil Last on Wed May 19, 2010 1:58 pm

I believe it was Jim Brown's view that APL2 rationalised the use of Parentheses such that "parentheses are for grouping. Period."

APL2's switching of the "strength" of Bracket and Vector binding was justified on the grounds that in nested vector:

vec0 vec1 vec2

if we want to index one or more of the sub vectors we would need brackets AND parentheses if vector binding were stronger than bracket:

vec0 vec1[x] vec2 ⍝ APL2
vec0(vec1[x])vec2 ⍝ Dyalog

The problem is that in order to save those unusual parentheses APL2 now requires all literal indexed vectors to be parenthesised:

5 4 6 3 7 2 8 1 9[x]   ⍝ APL (ISO 8485)
(5 4 6 3 7 2 8 1 9)[x] ⍝ APL2

Swings and roundabouts.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest