Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect explanation of the value returned by dyadic iota when no element is found #26

Closed
yakubin opened this issue Jun 21, 2022 · 2 comments

Comments

@yakubin
Copy link

yakubin commented Jun 21, 2022

In Glyphiary, there is the sentence:

A nifty feature is that if the right element isn’t found, the returned index is 1+≢⍺ – one more than the length of the left argument.

This is true only if the index origin is 1. However, this very chapter (and the entire book so far) starts with setting it to 0:

      ⎕IO ← 1
      staff⍳'Bob' 'David'
┌→──┐
│2 4│
└~──┘
      ≢staff
 
3
 
      ⎕IO ← 0
      staff⍳'Bob' 'David'
┌→──┐
│1 3│
└~──┘
      ≢staff
 
3

Therefore, the sentence should instead read something like:

A nifty feature is that if the right element isn’t found, the returned index is ≢⍺ – the length of the left argument.

Alternatively:

A nifty feature is that if the right element isn’t found, the returned index is ⎕IO+≢⍺ – sum of the index origin and the length of the left argument.

@yakubin
Copy link
Author

yakubin commented Jun 22, 2022

Similarly, in the explanation of Interval Index:

Similarly, elements greater than the last bin will end up with a bin number equal to the number of elements (note: not the number of bins) to the left:

And the following example is given:

      3 5 7 9⍸0 100
┌→───┐
│¯1 3│
└~───┘

There are 4 elements on the left side of and for 100 it returns 3, not 4. If we set ⎕IO to 1 on the other hand, the explanation is correct (for 100, but not for 0, which now gets 0 instead of -1):

      ⎕IO ← 1
      3 5 7 9⍸0 100
┌→──┐
│0 4│
└~──┘

@xpqz
Copy link
Owner

xpqz commented Nov 7, 2022

Thank you for pointing this out. I'll be sure to address this in the next update I make.

@xpqz xpqz closed this as completed in da6d428 Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants