> > What you wanted is simply: > (⊂w) is_anagram_of¨ cl
Thank you! I knew I must have been missing it, it should have been so simple! On Thu, 29 Jul 2021 at 23:42, <bug-apl-requ...@gnu.org> wrote: > Send Bug-apl mailing list submissions to > bug-apl@gnu.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.gnu.org/mailman/listinfo/bug-apl > or, via email, send a message with subject or body 'help' to > bug-apl-requ...@gnu.org > > You can reach the person managing the list at > bug-apl-ow...@gnu.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Bug-apl digest..." > > > Today's Topics: > > 1. Question on scalar extension of left arg (Russtopia) > 2. Re: Question on scalar extension of left arg (Kacper Gutowski) > 3. Re: Question on scalar extension of left arg (Russtopia) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 29 Jul 2021 22:48:52 -0700 > From: Russtopia <rma...@gmail.com> > To: bug-apl@gnu.org > Subject: Question on scalar extension of left arg > Message-ID: > < > can4ycu_7un-iassheqcjjgdu2mzzgxb4lnzjs1_xpjc1+w3...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hello, I am trying an exercise that finds anagrams of a word from a list of > candidate words. > > I am having issues with scalar extension of the left arg, which I thought > should automatically repeat the scalar left arg to match each item in the > right vector arg. It seems to work only if I do the expansion manually > (that is, repeat the left arg explicitly rather than let APL do it). > > (If formatting below is not readable, please convert it to a fixed-with > font) > > w > > ┌→─────┐ > > │listen│ > > └──────┘ > > cl > > ┌→────────────────────────────────────────────┐ > > │┌→──────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > > ││enlists│ │google│ │inlets│ │banana│ │tinsel││ > > │└───────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > > └∊────────────────────────────────────────────┘ > > ⎕cr 'is_anagram_of' > > ┌→──────────────────────────────┐ > > ↓r ← word is_anagram_of other │ > > │r ← word[⍋word] ≡ other[⍋other]│ > > └───────────────────────────────┘ > > w is_anagram_of cl > > 0 > > w is_anagram_of ¨ cl ⍝ <-- Should this not implicitly expand > > left arg? > > DOMAIN ERROR > > is_anagram_of[1] r←word[⍋word]≡other[⍋other] > > ^ ^ > > w w w w w is_anagram_of cl ⍝ <-- this works, w w w w w matches > > ⍴cl > > 0 > > w w w w w is_anagram_of ¨ cl > > ┌→────────┐ > > │0 0 1 0 1│ > > └─────────┘ > > (w w w w w is_anagram_of ¨ cl)/cl > > ┌→────────────────┐ > > │┌→─────┐ ┌→─────┐│ > > ││inlets│ │tinsel││ > > │└──────┘ └──────┘│ > > └∊────────────────┘ > > (∊1 (⍴cl))⍴⊂w > > ┌→───────────────────────────────────────────┐ > > ↓┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > > ││listen│ │listen│ │listen│ │listen│ │listen││ > > │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > > └∊───────────────────────────────────────────┘ > > w w w w w > > ┌→───────────────────────────────────────────┐ > > │┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > > ││listen│ │listen│ │listen│ │listen│ │listen││ > > │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > > └∊───────────────────────────────────────────┘ > > ((∊1 (⍴cl))⍴⊂w) is_anagram_of ¨ cl ⍝ <-- ?? Why does this not > > work as (w w w w w)? > > RANK ERROR > > ((∈1(⍴cl))⍴⊂w)is_anagram_of¨cl > > ^ ^ > > > Advice appreciated, > Thank you, > -Russ > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > https://lists.gnu.org/archive/html/bug-apl/attachments/20210729/61a06b9e/attachment.html > > > > ------------------------------ > > Message: 2 > Date: Fri, 30 Jul 2021 08:14:58 +0200 > From: Kacper Gutowski <mwgam...@gmail.com> > To: bug-apl@gnu.org > Subject: Re: Question on scalar extension of left arg > Message-ID: <yqoy4te7webhj...@hyper.mwgamera.name> > Content-Type: text/plain; charset=utf-8; format=flowed > > Looking at this post I think there is a tiny bug > in the implementation of each: > > (⍳6) {⍺,⍵}¨ ⍳5 > 1 1 2 2 3 3 4 4 5 5 > (⍳5) {⍺,⍵}¨ ⍳6 > INDEX ERROR > μ-Z__vA_LO_EACH_vB[2] (μ-N⊃μ-Z)←(μ-N⊃μ-A)μ-LO > ^ ^ > > I think both should give a LENGTH ERROR. > > > On Thu, Jul 29, 2021 at 10:48:52PM -0700, Russtopia wrote: > >> w > >> ┌→─────┐ > >> │listen│ > >> └──────┘ > >> cl > >> ┌→────────────────────────────────────────────┐ > >> │┌→──────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > >> ││enlists│ │google│ │inlets│ │banana│ │tinsel││ > >> │└───────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > >> └∊────────────────────────────────────────────┘ > > >> w is_anagram_of ¨ cl ⍝ <-- Should this not implicitly expand > >>left arg? > > Look at the shapes, w is not a scalar but a vector of length 6 and cl is > a vector of length 5. No scalar extension is possible, but a length error. > > What you wanted is simply: > > (⊂w) is_anagram_of¨ cl > 0 0 1 0 1 > > >> (∊1 (⍴cl))⍴⊂w > >> ┌→───────────────────────────────────────────┐ > >> ↓┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > >> ││listen│ │listen│ │listen│ │listen│ │listen││ > >> │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > >> └∊───────────────────────────────────────────┘ > >> w w w w w > >> ┌→───────────────────────────────────────────┐ > >> │┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > >> ││listen│ │listen│ │listen│ │listen│ │listen││ > >> │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > >> └∊───────────────────────────────────────────┘ > > These are not the same. See that arrow on the left border of boxed > representation? > > >> ((∊1 (⍴cl))⍴⊂w) is_anagram_of ¨ cl ⍝ <-- ?? Why does this not > >>work as (w w w w w)? > >> RANK ERROR > >> ((∈1(⍴cl))⍴⊂w)is_anagram_of¨cl > >> ^ ^ > > w w w w w ←→ 5⍴⊂w ⍝ a 5-element vector > ((∊1 (⍴cl))⍴⊂w) ←→ 1 5⍴⊂w ⍝ a 1-by-5 matrix > > -k > > > > ------------------------------ > > Message: 3 > Date: Thu, 29 Jul 2021 23:42:04 -0700 > From: Russtopia <rma...@gmail.com> > To: bug-apl@gnu.org > Subject: Re: Question on scalar extension of left arg > Message-ID: > < > can4ycu9zrgdpb-hhjjrx2atnjtfs0oc+6p9n3o+cqffnapm...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Please excuse my bad form in replying to my own message. I see now there is > a subtle difference in the two expressions (namely, a down-arrow in the > left edge of the outermost box in the second form below): > > (w w w w w) > > ┌→───────────────────────────────────────────┐ > > │┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > > ││listen│ │listen│ │listen│ │listen│ │listen││ > > │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > > └∊───────────────────────────────────────────┘ > > ⍴(w w w w w) > > ┌→┐ > > │5│ > > └─┘ > > (∊1 (⍴cl))⍴⊂w > > ┌→───────────────────────────────────────────┐ > > ↓┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > > ││listen│ │listen│ │listen│ │listen│ │listen││ > > │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > > └∊───────────────────────────────────────────┘ > > ⍴(∊1 (⍴cl))⍴⊂w > > ┌→──┐ > > │1 5│ > > └───┘ > > ⍴((∊1 (⍴cl))⍴⊂w)[1;] ⍝ Very ugly, but this seems to coerce to > > match the above ⍴(w w w w w) > > ┌→┐ > > │5│ > > └─┘ > > > I suppose this is the reason one form works as an argument to my function, > where the other does not. > > I still seek to understand why APL does not apply scalar extension on the > left arg though, to avoid needing either of these manual expansions to > match a single left arg with the list of right args. > > -Russ > > > On Thu, 29 Jul 2021 at 22:48, Russtopia <rma...@gmail.com> wrote: > > > Hello, I am trying an exercise that finds anagrams of a word from a list > > of candidate words. > > > > I am having issues with scalar extension of the left arg, which I thought > > should automatically repeat the scalar left arg to match each item in the > > right vector arg. It seems to work only if I do the expansion manually > > (that is, repeat the left arg explicitly rather than let APL do it). > > > > (If formatting below is not readable, please convert it to a fixed-with > > font) > > > > w > >> ┌→─────┐ > >> │listen│ > >> └──────┘ > >> cl > >> ┌→────────────────────────────────────────────┐ > >> │┌→──────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > >> ││enlists│ │google│ │inlets│ │banana│ │tinsel││ > >> │└───────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > >> └∊────────────────────────────────────────────┘ > >> ⎕cr 'is_anagram_of' > >> ┌→──────────────────────────────┐ > >> ↓r ← word is_anagram_of other │ > >> │r ← word[⍋word] ≡ other[⍋other]│ > >> └───────────────────────────────┘ > >> w is_anagram_of cl > >> 0 > >> w is_anagram_of ¨ cl ⍝ <-- Should this not implicitly expand > >> left arg? > >> DOMAIN ERROR > >> is_anagram_of[1] r←word[⍋word]≡other[⍋other] > >> ^ ^ > >> w w w w w is_anagram_of cl ⍝ <-- this works, w w w w w matches > >> ⍴cl > >> 0 > >> w w w w w is_anagram_of ¨ cl > >> ┌→────────┐ > >> │0 0 1 0 1│ > >> └─────────┘ > >> (w w w w w is_anagram_of ¨ cl)/cl > >> ┌→────────────────┐ > >> │┌→─────┐ ┌→─────┐│ > >> ││inlets│ │tinsel││ > >> │└──────┘ └──────┘│ > >> └∊────────────────┘ > >> (∊1 (⍴cl))⍴⊂w > >> ┌→───────────────────────────────────────────┐ > >> ↓┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > >> ││listen│ │listen│ │listen│ │listen│ │listen││ > >> │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > >> └∊───────────────────────────────────────────┘ > >> w w w w w > >> ┌→───────────────────────────────────────────┐ > >> │┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐ ┌→─────┐│ > >> ││listen│ │listen│ │listen│ │listen│ │listen││ > >> │└──────┘ └──────┘ └──────┘ └──────┘ └──────┘│ > >> └∊───────────────────────────────────────────┘ > >> ((∊1 (⍴cl))⍴⊂w) is_anagram_of ¨ cl ⍝ <-- ?? Why does this not > >> work as (w w w w w)? > >> RANK ERROR > >> ((∈1(⍴cl))⍴⊂w)is_anagram_of¨cl > >> ^ ^ > > > > > > Advice appreciated, > > Thank you, > > -Russ > > > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: < > https://lists.gnu.org/archive/html/bug-apl/attachments/20210729/d6cdee26/attachment.html > > > > ------------------------------ > > Subject: Digest Footer > > _______________________________________________ > Bug-apl mailing list > Bug-apl@gnu.org > https://lists.gnu.org/mailman/listinfo/bug-apl > > > ------------------------------ > > End of Bug-apl Digest, Vol 94, Issue 7 > ************************************** >