Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is `{⊂⍵}` different from just `⊂`?

I'm reading through Hui and Kromberg's recent "APL Since 1978" and in the discussion of (stencil) they give the following example:

      {⊂⍵}⌺5⊢'abcde'
   abc   abcd  abcde  bcde   cde

Why is the {⊂⍵} needed over just ? I'm still pretty new to APL but I would naively think that in general {f⍵} should be equivalent to f when called monadically.

Empirically I can see that's not the case:

      ⊂⌺5⊢'abcde'
DOMAIN ERROR
      ⊂⌺5⊢'abcde'
      ∧

But I don't understand why.

like image 978
ssfrr Avatar asked Jun 28 '20 12:06

ssfrr


1 Answers

You're absolutely right that {⊂⍵} is equivalent to when called monadically, however as per the documentation:

f is invoked dyadically with a vector left argument indicating for each axis the number of fill elements and on what side; positive values mean that the padding precedes the array values, negative values mean that the padding follows the array values.

We can illustrate this by making the function return the enclosure of both arguments together:

      {⊂⍺ ⍵}⌺5⊢'abcde'
┌─────────┬─────────┬─────────┬──────────┬──────────┐
│┌─┬─────┐│┌─┬─────┐│┌─┬─────┐│┌──┬─────┐│┌──┬─────┐│
││2│  abc│││1│ abcd│││0│abcde│││¯1│bcde │││¯2│cde  ││
│└─┴─────┘│└─┴─────┘│└─┴─────┘│└──┴─────┘│└──┴─────┘│
└─────────┴─────────┴─────────┴──────────┴──────────┘

This left argument is designed to fit the requirements as left argument of so the added padding can be removed easily:

      {⊂⍺↓⍵}⌺5⊢'abcde'
┌───┬────┬─────┬────┬───┐
│abc│abcd│abcde│bcde│cde│
└───┴────┴─────┴────┴───┘

If you want a tacit operand instead of {⊂⍵} then you can use ⊢∘⊂ (which is equivalent to {⍺⊢⊂⍵} and therefore {⊂⍵}) or, in version 18.0, ⊂⍤⊢ (which is equivalent to {⊂⍺⊢⍵} and therefore {⊂⍵}).

like image 100
Adám Avatar answered Nov 10 '22 22:11

Adám