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

Happy reading :-)
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


Reply via email to