diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-05 17:19:14 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-06-05 17:19:14 -0400 |
| commit | 8b115bd20d7a91361a7fe87f293a8a53ff12406c (patch) | |
| tree | 44e4bd404532d007b5f2bdbdfc392c1698a20a49 /doc/pick.md | |
| parent | d6b2e28359a2e0f5f8a0f98782b30d34c18138a1 (diff) | |
Editing continues
Diffstat (limited to 'doc/pick.md')
| -rw-r--r-- | doc/pick.md | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/doc/pick.md b/doc/pick.md index 254c64ec..bc30b930 100644 --- a/doc/pick.md +++ b/doc/pick.md @@ -4,7 +4,7 @@ Pick (`β`) chooses elements from `π©` based on [index](indices.md) lists from `π¨`. `π¨` can be a plain list, or even one number if `π©` is a list, in order to get one element from `π©`. It can also be an array of index lists, or have deeper array structure: each index list will be replaced with the element of `π©` at that index, effectively applying to `π¨` at [depth](depth.md#the-depth-modifier) 1. -With no `π¨`, monadic `βπ©` takes the first element of `π©` in index order, with an error if `π©` is empty. +The one-argument form is called First, and `βπ©` takes the first element of `π©` in index order, with an error if `π©` is empty. While sometimes "scatter-point" indexing is necessary, using Pick to select multiple elements from `π©` is less array-oriented than [Select](select.md) (`β`), and probably slower. Consider rearranging your data so that you can select along axes instead of picking out elements. @@ -21,7 +21,7 @@ A negative number `π¨` behaves like `π¨+β π©`, so that `Β―1` will select Β―2 β 0βΏ1βΏ2βΏ3βΏ4 Β―2 β "abc" -Making `π©` a list is only a special case. In general `π¨` can be a list of numbers whose length is `π©`'s rank. So when `=π©` is 1, `π¨` can be length-1 list. For convenience, a number is also allowed, but not an enclosed number (which could be confused with the nested case). +Making `π©` a list is only a special case. In general `π¨` can be a list of numbers whose length is `π©`'s rank. So when `=π©` is 1, `π¨` can be length-1 list. The case above where `π¨` is a number is a simplification, but an enclosed number `π¨` isn't allowed because it could be confused with the nested case described below. β¨2,0β© β β4βΏ5 @@ -31,22 +31,23 @@ Above we see that picking from the result of [Range](range.md) gives the index. 2βΏ0 β a 1βΏΒ―1 β a -This applies even if `π©` is a unit. By definition it has rank 0, so the only possible value for `π¨` is the empty list. This extracts an [enclosed](enclose.md) element, and returns an atom unchangedβthe atom is promoted to an array by enclosing it, then the action of Pick undoes this. But there's rarely a reason to use this case, because the monadic form First accomplishes the same thing. +`π©` can even be a [unit](enclose.md#whats-a-unit). By definition it has rank 0, so the only possible value for `π¨` is the empty list. This extracts an [enclosed](enclose.md) element, and returns an atom unchangedβthe atom is promoted to an array by enclosing it, then the action of Pick undoes this. But there's rarely a reason to use this case, because the monadic form First accomplishes the same thing. β¨β© β <'a' β¨β© β 'a' ### First -With no left argument, `β` is called First, and performs a slight generalization of Pick with a default left argument `0Β¨β’π©`. For a non-empty array it returns the first element in index order. +With no left argument, `β` is called First, and is the same as Pick with a default left argument `0Β¨β’π©`. For a non-empty array it returns the first element in index order. β <'a' β "First" β β4βΏ2βΏ5βΏ1 -If `π©` is empty then First results in an error, like Pick. +And if `π©` is empty then First results in an error. β "" + β β’Ο In APL it's common to get the last element of a list with an idiom that translates to `ββ½`, or First-[Reverse](reverse.md). In BQN the most straightforward way is to select with index `Β―1` instead. I also sometimes use [Fold](fold.md) with the Right [identity function](identity.md). |
