bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] West way to remove substrings?


From: mwgamera
Subject: Re: [Bug-apl] West way to remove substrings?
Date: Tue, 14 Mar 2017 16:41:11 +0100

How about
      {⊃,/(¯1+↑⍴⍺)↓¨(~⍺⍷⍵)⊂⍵←⍺,⍵}
It doesn't rely on ⎕IO setting.

-k

On 14 March 2017 at 15:20, Elias Mårtenson <address@hidden> wrote:
> In a discussion on the #lisp IRC channel recently, someone wanted to remove
> a certain substring from a larger string. In Lisp, the solution is to simply
> use cl-ppcre and remove by regex.
>
> But, I started thinking about how to do this in APL, and this is what I came
> up with:
>
>       RemoveSubstrings ← {,/ ⍵ ⊂⍨ ↑~∨/ (-⍳⍴⍺) °.⌽ ⊂⍺⍷⍵}
>
> Is this a good way of solving the problem? I realise that I have a bug when
> the resulting string is empty:
>
>       "foo" RemoveSubstrings "foo"
> DOMAIN ERROR
> λ1[1]  λ←,/⍵⊂⍨↑∼∨/(-⍳⍴⍺)°.⌽⊂⍺⋸⍵
>          ^ ^
>
> Does anyone have a better solution?
>
> Regards,
> Elias



reply via email to

[Prev in Thread] Current Thread [Next in Thread]