aya-lang/aya

Consider changing "not-found" behavior of `N`/`.N`

nick-paul opened this issue · 1 comments

Originally brought up by @BlazingTwist here

The N operator returns -1 if it cannot find a value in a list. More recently, negative index support was added to Aya. -1 is no longer a good candidate for a default value since it is a valid index.

Possible options:

  • N return length(list)+1 for not found
    • More difficult to use N as a basic contains operator since the index will need to be compared with the length of the list instead of with a known constant
      • Current way to check if a value is in a list: N0<!
      • New way to check if a value is in a list (compare with length of list): N\.E@=
  • Possibly utilize unused :N operator for plain contains checking (return 1 if item is in list, 0 otherwise)
  • N return length(list)+1 for not found
    • More difficult to use N as a basic contains operator since the index will need to be compared with the length of the list instead of with a known constant

If you have the index-of operators return 0 list EB -, that index will be out of bounds while still supporting N0<!