aya-lang / aya

Pocket sized programs
MIT License
54 stars 3 forks source link

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

Closed nick-paul closed 2 years ago

nick-paul commented 2 years ago

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:

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