[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-apl] Substring replacement in APL
From: |
Hans-Peter Sorge |
Subject: |
Re: [Bug-apl] Substring replacement in APL |
Date: |
Wed, 13 Apr 2016 20:19:14 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 |
Am 12.04.2016 um 13:18 schrieb Jay Foad:
> 'foobartestfootest' replace 'foo' 'xy'
Hi,
there are some corner conditions ((1↓u),⍺ contains u, but ⍺ does not):
replace←{(⍴v)↓∊(⊂v),¨(↑⍴u)↓¨(+\u⍷a)⊂a←u,⍺⊣(u v)←⍵}
'foobartestfootest' replace 'foo' 'xy'
xybartestxytest
'foobartestfootest' replace 'ofo' 'xy'
xyobartestfootest
Fixes it:
replace←{((0=⍴z)/a),z←∊((e×⍴v)↑¨⊂v),¨((⍴u)×e←+/¨(1+p)⊂p)↓¨(1++\p←u⍷a)⊂a←⍺⊣(u
v)←⍵}
'foobartestfootest' replace 'ofo' 'xy'
foobartestfootest
Greetings,
HP