Works in APL2 but not in Dyalog APL

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Works in APL2 but not in Dyalog APL

Postby anilkasat on Mon Jan 23, 2012 9:14 pm

I have written the following code in APL2 on mainframe and it gives me desired results

input1
144 81
544 81
84
85
85
85
124
275
542
544
545
533
135
136
155
156
134
530
84
525
526
249
250 12 12 181 41 159 0000 000000 13124
526 23 52 356 26 213 6213
#.Display input1
.→---------------------------------------------------------.
| .→--. .→-. .→-. .→--. .→-. .→--. .→---. .→-----. .→----. |
| ↓144| ↓ | ↓ | ↓ | ↓81| ↓ | ↓ | ↓ | ↓ | |
| |544| | | | | | | |81| | | | | | | | | |
| | | | | | | | | |84| | | | | | | | | |
| | | | | | | | | |85| | | | | | | | | |
| | | | | | | | | |85| | | | | | | | | |
| | | | | | | | | |85| | | | | | | | | |
| |124| | | | | | | | | | | | | | | | | |
| |275| | | | | | | | | | | | | | | | | |
| |542| | | | | | | | | | | | | | | | | |
| |544| | | | | | | | | | | | | | | | | |
| |545| | | | | | | | | | | | | | | | | |
| |533| | | | | | | | | | | | | | | | | |
| |135| | | | | | | | | | | | | | | | | |
| |136| | | | | | | | | | | | | | | | | |
| |155| | | | | | | | | | | | | | | | | |
| |156| | | | | | | | | | | | | | | | | |
| |134| | | | | | | | | | | | | | | | | |
| |530| | | | | | | | | | | | | | | | | |
| | | | | | | | | |84| | | | | | | | | |
| |525| | | | | | | | | | | | | | | | | |
| |526| | | | | | | | | | | | | | | | | |
| |249| | | | | | | | | | | | | | | | | |
| |250| |12| |12| |181| |41| |159| |0000| |000000| |13124| |
| |526| |23| |52| |356| |26| |213| |6213| | | | | |
| '---' '--' '--' '---' '--' '---' '----' '------' '-----' |
'∊---------------------------------------------------------'
⍴input1
9
⍴¨input1
24 3 24 2 24 2 24 3 24 2 24 3 24 4 24 6 24 5

((∊input1=' ')/∊input1)←'-'

#.Display input1
.→---------------------------------------------------------.
| .→--. .→-. .→-. .→--. .→-. .→--. .→---. .→-----. .→----. |
| ↓144| ↓--| ↓--| ↓---| ↓81| ↓---| ↓----| ↓------| ↓-----| |
| |544| |--| |--| |---| |81| |---| |----| |------| |-----| |
| |---| |--| |--| |---| |84| |---| |----| |------| |-----| |
| |---| |--| |--| |---| |85| |---| |----| |------| |-----| |
| |---| |--| |--| |---| |85| |---| |----| |------| |-----| |
| |---| |--| |--| |---| |85| |---| |----| |------| |-----| |
| |124| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |275| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |542| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |544| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |545| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |533| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |135| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |136| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |155| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |156| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |134| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |530| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |---| |--| |--| |---| |84| |---| |----| |------| |-----| |
| |525| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |526| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |249| |--| |--| |---| |--| |---| |----| |------| |-----| |
| |250| |12| |12| |181| |41| |159| |0000| |000000| |13124| |
| |526| |23| |52| |356| |26| |213| |6213| |------| |-----| |
| '---' '--' '--' '---' '--' '---' '----' '------' '-----' |
'∊---------------------------------------------------------'
⍴input1
9

Basically, I wanted to put '-' in input1 wherever there is a ' '. It worked fine in APL2. But when I try to do the same thing in Dyalog APL, it gives me a syntax error. For the same input1, I need the same output as shown above in Dyalog APL.

((∊input1 =' ')/∊input1 )←'-'
SYNTAX ERROR
((∊input1=' ')/∊input1)←'-'


Can some please share their ideas on what needs to be changed in Dyalog APL in order to achieve the same result with the same input1.

Thanks in advance.
anilkasat
 
Posts: 6
Joined: Tue Dec 13, 2011 8:23 am

Re: Works in APL2 but not in Dyalog APL

Postby Morten|Dyalog on Tue Jan 24, 2012 7:20 am

There are a few cases of APL2 "selective specification" which are not supported in Dyalog APL. We are looking at closing this gap, possibly this year - but are not ready to announce this yet.

It is hard to come up with a completely general replacement for this expression, but in your specific case, I believe the following function will do the same thing. It may well be more efficient than the selective specification would be, too - but of course I can't measure that:

      charsubst←{a←⎕UCS ⍺ ⋄ ⎕UCS¨{⍵+(--/a)×⍵=1↑a}⎕UCS¨⍵}
' -' charsubst input1

.→---------------------------------------------------------.
| .→--. .→-. .→-. .→--. .→-. .→--. .→---. .→-----. .→----. |
| ↓144| ↓--| ↓--| ↓---| ↓81| ↓---| ↓----| ↓------| ↓-----| |
| |544| |--| |--| |---| |81| |---| |----| |------| |-----| |
...etc...
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: Works in APL2 but not in Dyalog APL

Postby anilkasat on Tue Jan 24, 2012 7:39 am

Thanks Morten. This did solve the problem for me. However, I came up with one more solution as well.

Disclose Function

res←Disclose nestarray;i;X
i←1

⍝ you may need to copy from below to EEFALUPDRED for R5 variable

res←0⍴' ' ⍝ prepare res with empty axis for catenation
:Repeat
X←i⊃nestarray ⍝ disclose components one by one from nestarray
((,X=' ')/,X)←'-' ⍝ this you know !!!
res,←⊂X ⍝ pack and catenate each component
i+←1 ⍝ increment for no of components inside nestarray
:Until i>⍴nestarray ⍝ total no of times the increment should be done

Disclose input1 --- gives me the result.
anilkasat
 
Posts: 6
Joined: Tue Dec 13, 2011 8:23 am

Re: Works in APL2 but not in Dyalog APL

Postby Phil Last on Tue Jan 24, 2012 8:44 am

Also for performing non-scalar operations on the simple subarrays of an arbitrarily nested structure the dfns workspace has a number of functions (see saw: http://dfns.dyalog.com/n_saw.htm) that might help.
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: Works in APL2 but not in Dyalog APL

Postby Veli-Matti on Wed Jan 25, 2012 2:32 pm

If I understood the problem correctly, the following might be the solution for this specific case:

      aa←10 10⍴1 2 3 '' 5 6
((∊0∊¨⍴¨aa)/,aa)←'-'
aa
1 2 3 - 5 6 1 2 3 -
5 6 1 2 3 - 5 6 1 2
3 - 5 6 1 2 3 - 5 6
1 2 3 - 5 6 1 2 3 -
5 6 1 2 3 - 5 6 1 2
3 - 5 6 1 2 3 - 5 6
1 2 3 - 5 6 1 2 3 -
5 6 1 2 3 - 5 6 1 2
3 - 5 6 1 2 3 - 5 6
1 2 3 - 5 6 1 2 3 -


..but I have been wrong before.
The enss function in the aforementioned dfns workspace might help, too.

-Veli-Matti
Veli-Matti
 
Posts: 93
Joined: Sat Nov 28, 2009 3:12 pm

Re: Works in APL2 but not in Dyalog APL

Postby Morten|Dyalog on Sun Mar 25, 2012 7:42 am

FYI: This example [((∊x=' ')/∊x)←'-'] now works in the latest Beta release of Dyalog Version 13.1. There are still a few cases of selective specification that do not work, we are planning to knock them off during 2012.
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

Re: Works in APL2 but not in Dyalog APL

Postby michaelk on Thu Mar 29, 2012 4:26 am

This will be a great enhancement. Looking forward to 13.1.
michaelk
 
Posts: 34
Joined: Wed Feb 10, 2010 8:38 am


Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest