Mixed views on mix

How to move APL code to Dyalog
Post Reply
sjt
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Mixed views on mix

Post by sjt »

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?
DanB|Dyalog

Re: Mixed views on mix

Post by DanB|Dyalog »

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?
sjt
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Post by sjt »

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
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Mixed views on mix

Post by Phil Last »

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

Migration To or From Dyalog?
sjt
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Post by sjt »

To. (You crazy?)
Jay|Dyalog

Re: Mixed views on mix

Post by Jay|Dyalog »

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.
sjt
Posts: 21
Joined: Fri Nov 05, 2010 6:26 am

Re: Mixed views on mix

Post by sjt »

Thanks to all for corrections and comments.

Any thoughts on how to deal with this difference when migrating to Dyalog?
User avatar
Phil Last
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Mixed views on mix

Post by Phil Last »

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.
Post Reply