xpqz / learnapl

Introduction to Dyalog APL: https://xpqz.github.io/learnapl
Other
126 stars 11 forks source link

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

Closed yakubin closed 1 year ago

yakubin commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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