APL2 Code in Dyalog APL not working

How to move APL code to Dyalog

APL2 Code in Dyalog APL not working

Postby anilkasat on Sat Jan 14, 2012 10:51 am

This code gives desired results in IBM APL2 on Mainframes, but LENGTH
ERROR in Dyalog APL 12.1


APL2 Code:


      X←23 3 ⍴'  '   (23 ROWS 3 COLUMS OF SPACES MATRIX)


      (~∧/X∊' ?'⍀(1 2 ⍴'0'))


The result of above statement in APL2 is 23 rows and 2 column matrix
of spaces.


My ultimate objective is to get result as no of columns of right hand
argument and no of rows of left argument. I mean 23 rows and 2 column
matrix of space.


I tried with below logic, but I am getting 0's as result instead
spaces, only when my left argument is an array of numeric 1. If its
is 0, then it gives LENGTH ERROR


      (y⍀((⍴y),2)⍴'0')
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00

Can someone please help me in resolving this?
anilkasat
 
Posts: 6
Joined: Tue Dec 13, 2011 8:23 am

Re: APL2 Code in Dyalog APL not working

Postby Morten|Dyalog on Sun Jan 15, 2012 9:06 am

I think you have a missing pair of parentheses in your first example, but I do agree that there may be a problem in that:

      1 1 1\'X'
XXX

but

      1 1 1⍀1 2⍴'X'
LENGTH ERROR

I will investigate and get back to you. Meanwhile, I think you can work around the problem by defining:

      apl2expandrows←{⍺⍀((+/⍺),¯1↑⍴⍵)⍴⍵}
1 1 1 apl2expandrows 1 2⍴'X'
XX
XX
XX
1 0 1 apl2expandrows 1 2⍴'X'
XX

XX
User avatar
Morten|Dyalog
 
Posts: 462
Joined: Tue Sep 09, 2008 3:52 pm

Re: APL2 Code in Dyalog APL not working

Postby Phil Last on Sun Jan 15, 2012 1:06 pm

Slightly more generally applicable:
      apl2expandrows←{⍺⍀(+/⍺)⌿⍵}
Though I don't agree that it's a "problem" that can be fixed unless Dyalog want to go the whole way and permit "scalar" extension wherever there is a dimension of 1.

For instance APL*PLUS used to allow inner product with a right argument having first dimension of 1 whatever else the shapes were. The data were effectively replicated to the trailing dimension of the left argument without taking up additional workspace.

It appears that APL2 also allows this though I suspect there are many other places where this could be done but isn't.

I doubt if any interpreter permits:
      (2 3⍴⍳4),,5
LENGTH ERROR
(2 3⍴⍳4),,5
Candidates would include
      , ⍪ / ⌿ \ ⍀ ,[] ⍪[] /[] ⌿[] \[] ⍀[]
I should see it as a mistake to do this in one or two places without a commitment to do it throughout.

Personally I think it's better without.

I suspect the rank operator is the probably best way to do any of these.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: APL2 Code in Dyalog APL not working

Postby anilkasat on Sun Jan 15, 2012 7:49 pm

Thanks a lot Morten and Phil.

Both of your suggestions worked for me and resolved my issue.

Cheers..Anil
anilkasat
 
Posts: 6
Joined: Tue Dec 13, 2011 8:23 am

Re: APL2 Code in Dyalog APL not working

Postby Phil Last on Mon Jan 16, 2012 1:46 pm

Apologies for my "Slightly more generally applicable" claim for the above. "Differently applicable" would have been a better description. Morten's works in 2d for both the single and the multiple row cases. Mine works only for the single row case but extends into more than 2 dimensions.
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 1 guest