Type | Wish | Status | built | Date | 14-May-2010 21:08 |
---|---|---|---|---|---|
Version | r3 master | Category | Native | Submitted by | Graham |
Platform | All | Severity | minor | Priority | normal |
Summary | Allow INDEX? to take none as an argument, return none |
---|---|
Description |
The same argument that was put forth to make EMPTY? take the none argument could apply to INDEX? as well: INDEX? none could return none. The advantage would be to simplify the use of INDEX? in code patterns like those shown below. See http://www.rebol.net/r3blogs/0315.html for EMPTY? none, #1626 for LENGTH? and #1627 for APPEND and INSERT. |
Example code |
; Desired behavior >> index? none == none ; Instead of this b: either b: find series var [index? b] [default] ; I can then do this b: any [index? find series var default] |
Assigned to | n/a | Fixed in | r3 master | Last Update | 23-Jan-2013 00:44 |
---|
Comments | |
---|---|
(0002368)
BrianH 14-May-2010 21:44 |
The disadvantage to this is that INDEX? would occasionally return none, rather than always an integer (no, don't change the proposal to return anything other than none, it's the only sensible return value in this case). This means that code that needs to rely on integer data being there would have to check for that. This is not a big problem in R3 though because we can use ASSERT, or code like the EITHER example code.
So its either a function that forces you to use code like the EITHER pattern above all the time, or a function that only requires you to use it where appropriate but also requires you to *remember* this. The community's answer to the EMPTY? none question is probably a good guideline to follow: We prefer flexibility in R3, even if it can count as a gotcha, and can check things ourselves if we need to. |
(0002395)
meijeru 19-Jun-2010 11:45 |
I second the NONE solution whole-heartedly. I had myself written a function index?find which produces 0 for the default (I have quite a few reusable snippets of code from another language, in which the not found result for index was always 0).
|
(0002411)
BrianH 30-Jun-2010 06:59 |
An INDEX? of 0 might erroneously be considered possible in REBOL, though it actually is not. If the value is immediately used in math, the programmer might never realize their code is buggy.
It is better to return #[none] here because the error the #[none] will trigger later if it is not screened for will be immensely valuable to developers trying to figure out what is wrong with their code. This is a proposal to allow the developer to automatically adjust for errors with simpler code, not to make bugs impossible to find. |
(0002618)
BrianH 20-Oct-2010 03:48 |
Not changed in alpha 108. |
(0003376)
Graham 19-Jan-2013 06:17 |
Time to add this in now. |
(0003378)
abolka 20-Jan-2013 03:07 |
I submitted an implementation of `INDEX? none` as proposed above:
https://github.com/rebol/r3/pull/67 (I took Carl having marked this as "built" once as sufficient indication that an implementation as proposed above is desired.) |
Date | User | Field | Action | Change |
---|---|---|---|---|
23-Jan-2013 00:44 | Graham | Status | Modified | reviewed => built |
23-Jan-2013 00:44 | Graham | Fixedin | Modified | => r3 master |
23-Jan-2013 00:44 | Graham | Version | Modified | alpha 99 => r3 master |
20-Jan-2013 03:10 | abolka | Comment : 0003378 | Modified | - |
20-Jan-2013 03:07 | abolka | Comment : 0003378 | Added | - |
19-Jan-2013 06:17 | Graham | Comment : 0003376 | Added | - |
20-Oct-2010 03:48 | BrianH | Comment : 0002618 | Added | - |
20-Oct-2010 03:48 | BrianH | Status | Modified | built => reviewed |
20-Oct-2010 03:48 | BrianH | Fixedin | Modified | alpha 108 => none |
21-Sep-2010 19:50 | carl | Fixedin | Modified | => alpha 108 |
21-Sep-2010 19:50 | carl | Status | Modified | reviewed => built |
30-Jun-2010 06:59 | BrianH | Comment : 0002411 | Added | - |
30-Jun-2010 06:51 | BrianH | Description | Modified | - |
19-Jun-2010 11:45 | meijeru | Comment : 0002395 | Added | - |
14-May-2010 21:46 | BrianH | Comment : 0002368 | Modified | - |
14-May-2010 21:44 | BrianH | Comment : 0002368 | Added | - |
14-May-2010 21:32 | BrianH | Status | Modified | submitted => reviewed |
14-May-2010 21:32 | BrianH | Code | Modified | - |
14-May-2010 21:32 | BrianH | Description | Modified | - |
14-May-2010 21:32 | BrianH | Summary | Modified | allow index? to take none as an argument => Allow INDEX? to take none as an argument, return none |
14-May-2010 21:08 | Graham | Ticket | Added | - |