bug-apl
[Top][All Lists]

## Re: APL2 code no longer works

 From: Hans-Peter Sorge Subject: Re: APL2 code no longer works Date: Mon, 21 Mar 2022 21:27:15 +0100 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

Hi,

Parse2 works for me. Albeit a rather simple test.
What was your data you parsed??

To explain:
r←(1↑d),(1↑d),v   ⍝⍝ add 2 time the delimiter in front of vector. If d is a vector, take the first element. If d is a matrix, fail.
⍝ normally use a different name than the return var. Just improves expresiveness.

⍝ in (1++\r ∊ d)⊂r
the _expression_ +\r ∊ d creates a 'partion vector' (pv) : 1 1 2 2⊂ 'abcd'  ←→ 'ab' 'cd'
here any 'd' adds one to pv . That is 1 2 . . . .3 .and so forth
The 1+ is superflous because  1 2 ... 3 ... does the same as 2 3 .... 4 .... (try 1200 1200 1201 1201⊂ 'abcd')

⍝  1↓¨ removes d from each vector

⍝  1 ↓ the removes the first fo the added (1↑d),(1↑d),

Having said that....

r←(v≠1⊃,d)⊂v does the same.  r←(v≠d)⊂v if you can insure d is scalar.

1 1 0 1 1 ⊂ 'ab,cd'  partitions at increasing numbers, removing '0 flagged' positions.

For Parse then I'd use

r←⊃(v≠1⊃,d)⊂v

Hans-Peter

Am 21.03.22 um 20:41 schrieb Blake McBride:
Greetings,

I wrote the following APL1 code a long time ago.

∇
[0]   r←d Parse v
[1]  ⍝ Convert vector v into a matrix breaking at delimiter d
[2]   r←(((0≠⍴v)×⍴r),⌈/r)⍴(,r∘.≥⍳⌈/r←¯1+(r,1+⍴v)-0,r←r/⍳⍴v)\(~r←v∈d)/v←,v
∇

It worked in 1981 and it works now.

I believe at some point someone on this list re-wrote the above in GNU APL (APL2) as follows:

∇
[0]   r←d Parse2 v
[1]  ⍝ break up vector v according to delimiter d into seperate arrays
[2]   r←1↓1↓¨(1++\r∊d)⊂r←(1↑d),(1↑d),v
∇

Interestingly, Parse2 used to work but doesn't anymore.  I suppose the APL2 logic in GNU APL has changed.  Two points:

1.  Can someone help me fix this?  (I don't know too much about APL2.)

2.  How good is APL2 if it can morph like this?  (APL1 seems much more straightforward and consistent and less open to interpretation.)

Thanks.

Blake McBride