Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

APL2 to Dyalog APL 12.1 Code Change

25 views
Skip to first unread message

Adarsh

unread,
Jan 13, 2012, 4:31:45 PM1/13/12
to
Hi All,

Can you guide me how to fix the below code in Dyalog APL.

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∊' ?'⍀(2 1 ⍴'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

Ellis Morgan

unread,
Jan 13, 2012, 6:09:56 PM1/13/12
to
I am not quite sure what you want to do, here is what I see in Dyalog
12.1 ...
X←23 3 ⍴' ' ⍝ (23 ROWS 3 COLUMS OF SPACES MATRIX)
(~∧/X∊' ?'⍀(2 1 ⍴'0'))
DOMAIN ERROR
(~∧/X∊' ?'⍀(2 1⍴'0'))

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


y←0 1[?5⍴2]
y
0 1 1 1 0
(y⍀((⍴y),2)⍴'0')
LENGTH ERROR
(y⍀((⍴y),2)⍴'0')

(y⍀((+/y),2)⍴'0')

00
00
00

⍴ (y⍀((+/y),2)⍴'0')
5 2

Phil Last

unread,
Jan 13, 2012, 6:41:07 PM1/13/12
to
> X←23 3 ⍴'  '   (23 ROWS 3 COLUMS OF SPACES MATRIX)
>
> (~∧/X∊' ?'⍀(2 1 ⍴'0'))

I seriously doubt if the above statement would work in any APL as the
left operand of ⍀ is a character vector.

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

is more likely being the correct domain but only if the sum of the
boolean left operand matches the first dimension of the right
argument, i.e. 2 in this case.

Again I doubt if the next statement would work anywhere unless y were
a vector of all 1s.

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

If they are the same length the left must all be 1s.

The only difference I can find between the APL2 and Dyalog
implementations is a degree of unitary extension in APL2 (a kind of
extension of scalar extension into more dimensions akin to that in
inner product in APL*PLUS) if the right argument has a first dimension
of 1. This is not allowed by Dyalog:

APL2:
1 0 1⍀1 4⍴⍳4
0 1 2 3
0 0 0 0
0 1 2 3

Dyalog:
1 0 1⍀1 4⍳4
LENGTH ERROR
1 0 1⍀1 4⍳4


Can you check that your statements have copied correctly to your
browser.

Adarsh

unread,
Jan 14, 2012, 4:49:42 AM1/14/12
to
Hi Phil,

Thanks for your prompt response !

It was a typo error from my side, you are right, the right hand
argument's first dimension is same as left one.

The code in APL2 looks as below

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

Now, my task is get the same output in Dyalog APL with the same input.
I need not limit myself to the same
operator in Dyalog APL. Can you suggest how should i do this !

Adarsh

unread,
Jan 14, 2012, 5:45:17 AM1/14/12
to
> 5 2- Dölj citerad text -
>
> - Visa citerad text -

Hi Ellis,

Thanks for your prompt response !

It was a typo error from my side, you are right, the right hand
argument's first dimension is same as left one.

The code in APL2 looks as below

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

Now, my task is to get the same output in Dyalog APL with the same

Ellis Morgan

unread,
Jan 14, 2012, 9:22:49 AM1/14/12
to
Here is one way ...

⎕IO
0

X←7 2⍴' ?'[?14⍴3]
X


??
?
?

??

(⊂X∧.=' ?')⌷[0]2 2⍴' 00'




00




⍝ hope this helps
⍝ or this may seem easier
⎕ML
0
↑(X∧.=' ?')\⊂'00'




00


⍝ end

Adarsh

unread,
Jan 14, 2012, 10:14:33 AM1/14/12
to
>       ⍝ end- Dölj citerad text -
>
> - Visa citerad text -

Ellis,

Your solution seems interesting!

But, I was looking ultimately a matrix with 23 rows and 2 columns. In
my example, the no of columns was decided by the right argument's (1 2
⍴'00') and rows by left argument's shape of boolean vector. This is
what the challenge in Dyalog APL to achive for me.

I tried with your above logic to suit my requirement. But, I'm getting
Lenght Error in most of the cases.

Please suggest if you have better approach.

Ellis Morgan

unread,
Jan 14, 2012, 12:30:10 PM1/14/12
to
In article
<ef550acd-9dfb-443b...@dp8g2000vbb.googlegroups.com>,
Adarsh <adars...@gmail.com> writes
>On 14 Jan, 15:22, Ellis Morgan <el...@ellismorgan.co.uk> wrote:
>> On Jan 14, 10:45 am, Adarsh <adarsha...@gmail.com> wrote:
>>
>>
>>
>>
>>
>> > On 14 Jan, 00:09, Ellis Morgan <el...@ellismorgan.co.uk> wrote:
>>
>> > > On Jan 13, 9:31 pm, Adarsh <adarsha...@gmail.com> wrote:
>>
>> > > > Hi All,
>>
>> > > > Can you guide me how to fix the below code in Dyalog APL.
>>
>> > > > This code gives desired results in IBM APL2 on Mainframes, but LENGTH
>> > > > ERROR in Dyalog APL 12.1
>>
>> > > > APL2 Code:
>>
>> > > > X0 >>
>> > > > (~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
>>
>> > > > (y0 >> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>> > > > 00
>>
>> > > I am not quite sure what you want to do, here is what I see in Dyalog
>> > > 12.1 ...
>> > >        X0 >> > >  (~0 >> > > DOMAIN ERROR
>> > >       (~0 >> > >           0 >> > >       (~0 >> > > LENGTH ERROR
>> > >       (~0 >> > >      0 >>
>> > >       y0 >> > >       y
>> > > 0 1 1 1 0
>> > >       (y0 >> > > LENGTH ERROR
>> > >       (y0 >> > >      0 >> > >       (y0 >>
>> > > 00
>> > > 00
>> > > 00
>>
>> > >     0 >> > > 5 2- Dölj citerad text -
>>
>> > > - Visa citerad text -
>>
>> > Hi Ellis,
>>
>> > Thanks for your prompt response !
>>
>> > It was a typo error from my side, you are right, the right hand
>> > argument's first dimension is same as left one.
>>
>> > The code in APL2 looks as below
>>
>> > (~0 >>
>> > Now, my task is to get the same output in Dyalog APL with the same
>> > input.
>> > I need not limit myself to the same
>> > operator in Dyalog APL. Can you suggest how should i do this !
>>
>> Here is one way ...
>>
>>       0 >> 0
>>
>>       X0 >>       X
>>
>> ??
>> ?
>>  ?
>>
>> ??
>>
>>       (0 >>
>> 00
>>
>>       0 >>       0 >>       0 >> 0
>>       0 >>
>> 00
>>
>>       0 >>
>> - Visa citerad text -
>
>Ellis,
>
>Your solution seems interesting!
>
>But, I was looking ultimately a matrix with 23 rows and 2 columns. In
>my example, the no of columns was decided by the right argument's (1 2
>0 >what the challenge in Dyalog APL to achive for me.
>
>I tried with your above logic to suit my requirement. But, I'm getting
>Lenght Error in most of the cases.
>
>Please suggest if you have better approach.
The number of rows in the answer will equal the number of elements in
"X". I chose 7 to save space. As Phil pointed out in this case APL2
allows you to treat one of something as if it were scalar. Dyalog is not
so generous (or careless, depending on your point of view) so to use a
similar idiom in Dyalog to the one you used in APL2 you must start with
a scalar. There are so many ways to get the answer you want that how you
go about it is a matter of choice and style. Once you know what is going
on it will be up to you how you go about it.
--
Ellis Morgan
0 new messages