Mixed views on mix

How to move APL code to Dyalog

Mixed views on mix

Postby sjt on Thu Apr 02, 2015 10:01 am

A little startled to discover mix appears to have different definitions in Dyalog and APL+Win and APLX. (A long-standing divergence from APL2?)
      V←'a' 'b' 'c' '' 'def'
⍴⊃5⍴V ⍝ APL+Win & APLX
5 3
⍴↑5⍴V ⍝ Dyalog
5 3
⍴⊃⍴V ⍝ APL+Win & APLX
4 0
⍴↑⍴V ⍝ Dyalog
4 1

The rule appears to be the width of the result is
      ⌈/≢¨⍵
in Dyalog and
      ⌈/↑¨⍴¨⍵
in APL+Win and APLX.

Ugly migration issue, I fear. Thoughts on handling it?
sjt
 
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Postby DanB|Dyalog on Thu Apr 02, 2015 8:12 pm

Did you mean ⍴↑⍴¨V? (⍴↑⍴V would be ,1)
Since ⍴ will return an 0 or 1 element for each shouldn't the result be a 5x1?
DanB|Dyalog
 

Re: Mixed views on mix

Postby sjt on Tue Apr 07, 2015 9:04 am

Oops. No (typo) I mean:
      ⍴⊃5⍴V ⍝ APL+Win & APLX
5 3
⍴↑5⍴V ⍝ Dyalog
5 3
⍴⊃4⍴V ⍝ APL+Win & APLX
4 0
⍴↑4⍴V ⍝ Dyalog
4 1
sjt
 
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Postby Phil Last on Tue Apr 07, 2015 9:26 am

Stephen wrote:Ugly migration issue, I fear. Thoughts on handling it?

Migration To or From Dyalog?
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Mixed views on mix

Postby sjt on Tue Apr 07, 2015 11:17 am

To. (You crazy?)
sjt
 
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Postby Jay|Dyalog on Wed Apr 08, 2015 8:20 am

sjt wrote:Oops. No (typo) I mean:
      ⍴⊃5⍴V ⍝ APL+Win & APLX
5 3
⍴↑5⍴V ⍝ Dyalog
5 3
⍴⊃4⍴V ⍝ APL+Win & APLX
4 0
⍴↑4⍴V ⍝ Dyalog
4 1


Yes, this is a long-standing difference between Dyalog and APL2. If you mix scalars and vectors the system has to find the maximum length of the vectors. APL2 ignores scalars when doing this; Dyalog treats them as vectors of length 1.

One point in favour of the "Dyalog way" is that it extends naturally to mixing items of any rank, by prefixing 1s to the shape of low-rank items to bring them all up to a common maximum rank. (And then bringing them all up to a common maximum shape along each axis as usual). This extension was implemented in Dyalog 14.0.
Jay|Dyalog
 

Re: Mixed views on mix

Postby sjt on Wed Apr 08, 2015 11:56 am

Thanks to all for corrections and comments.

Any thoughts on how to deal with this difference when migrating to Dyalog?
sjt
 
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Postby Phil Last on Wed Apr 08, 2015 2:36 pm

If you really want it to go on doing that after migration then
      di{↑(⌈/(⍴¨⍵)~⊂⍬)↑¨⍵}'⍬' '⍬' '' '123'
43--.
|⍬ |
|⍬ |
| |
|123|
'---'
di{↑(⌈/(⍴¨⍵)~⊂⍬)↑¨⍵}'⍬' '⍬' ''
30.
| |
| |
| |
'-'
di{↑(⌈/(⍴¨⍵)~⊂⍬)↑¨⍵}'⍬'
.-.
|⍬|
'-'
di{↑(⌈/(⍴¨⍵)~⊂⍬)↑¨⍵}''
0-.
| |
'-'

OK for mix of vectors and scalars but length error for situation mentioned by Jay. Could be worked in.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex


Return to Migrating from other Systems

Who is online

Users browsing this forum: No registered users and 0 guests