From 8b115bd20d7a91361a7fe87f293a8a53ff12406c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 5 Jun 2022 17:19:14 -0400 Subject: Editing continues --- doc/pick.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'doc/pick.md') 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). -- cgit v1.2.3