Type | Wish | Status | built | Date | 16-Sep-2013 20:00 |
---|---|---|---|---|---|
Version | r3 master | Category | Datatype | Submitted by | BrianH |
Platform | All | Severity | major | Priority | normal |
Summary | Have TO LOGIC! 0 return true |
---|---|
Description |
We currently need the TRUE? function to convert conditional values to their corresponding logic values, but why can't we use TO-LOGIC for this? The only thing that TO-LOGIC does differently is convert zero to false, while zero is conditionally truthy in Rebol. Treating zero as false is more C-like. If we have TO-LOGIC 0 return true instead, that would be more consistent with Rebol conditional semantics. As a side effect, we wouldn't need TRUE? anymore, except for code clarity. (Submitted to start the discussion. Suggested by #2053.) |
Example code |
>> to logic! 0 == true |
Assigned to | n/a | Fixed in | r3 master | Last Update | 26-Feb-2014 16:26 |
---|
Comments | |
---|---|
(0003972)
Ladislav 16-Sep-2013 20:16 |
I support this idea, since I never needed TO LOGIC! 0 to return FALSE. |
(0003973)
Ladislav 16-Sep-2013 20:20 |
Brian, you wrote: "We currently need the TRUE? function to convert conditional values to their corresponding logic values" - in my opinion it is important to realize why we need a function to convert conditional values to logic values.
It is not obvious why it is so, since there are many programming languages not having logic values at all and being "content" with just conditional values. So, we should really find out why? My idea is that the reason lies in the fact that there are logic operators accepting logic values but not conditional values. |
(0003974)
BrianH 16-Sep-2013 21:03 |
Well, let's start with the original purpose of the TRUE? function. When we were working on the initial version of the current R3-GUI, there was a need to store actual true/false values in fields in the GUI, so as to save the conditional result of a previous expression. We couldn't just store the original value because different datatypes were treated differently by the dialect. If TO-LOGIC behaved in a way that was consistent with conditional truthiness, we wouldn't have needed TRUE?. At the time we were being more strict about Rebol 2 compatibility, so it wouldn't have occurred to us to change TO-LOGIC. That time has passed.
Another situation would be when you are calling functions that take logic parameters, and behave differently when passed non-logic parameters if they are allowed at all. Sometimes you want to constrain the parameter types for better debugging, sometimes for future expansion, sometimes because the function is a command that isn't implemented in Rebol so it isn't as flexible. Sometimes the commands implement a dialect where logic values are treated differently than other values - conditional truthiness is more of a DO dialect thing, not necessarily supported in other dialects. TRUE? is used sometimes in APPLY blocks for passing values to the refinement arguments. It used to be necessary but those arguments are treated conditionally now, so it's mostly done to increase code clarity. I suppose some people might want to use TRUE? to convert values for use with the AND, OR or XOR operators, but I rarely do so because of how awkward it is to mix prefix and infix expressions in Rebol. It's much easier to use ALL and ANY instead, though there isn't really a prefix, conditional version of XOR. I suppose it could come in handy when using AND~, OR~ and XOR~, for those who use such functions. |
(0003978)
Ladislav 17-Sep-2013 13:13 |
Just a remainder:
>> make logic! 0 == false >> make logic! 1 == true |
(0003979)
BrianH 17-Sep-2013 19:03 |
Well, that means we won't have lost functionality. Unless you want to change MAKE too? |
(0003981)
abolka 17-Sep-2013 21:22 |
I'm in favour of amending TO LOGIC! functionality as well.
Not so much in favour of removing TRUE?, though. I think TRUE? reads far better in many cases than TO LOGIC!. |
(0003982)
BrianH 17-Sep-2013 21:44 |
TRUE? could be another word for TO-LOGIC, and both could be optional, not included in minimal builds. Just like FOUND?. |
(0003983)
fork 18-Sep-2013 02:44 |
In the further area of consistency, currently:
>> to integer! true == 1 >> to integer! false == 0 So long as we're bringing TO in line with Rebol's default worldview, then this should yield an error, just as with other wide types that pass for true... and picking an arbitrary one to map back from true and false is arbitrary: >> to integer! 12-Dec-2012 ** Script error: cannot MAKE/TO integer! from: 12-Dec-2012 ** Where: to ** Near: to integer! 12-Dec-2012 MAKE can keep the current behavior, by the rationale discussed that it doesn't need to follow "Rebol logic"... construction may be defined as seen fit: >> make integer! true == 1 >> make integer! false == 0 |
Date | User | Field | Action | Change |
---|---|---|---|---|
26-Feb-2014 16:29 | Ladislav | Comment : 0003980 | Removed | - |
26-Feb-2014 16:26 | Ladislav | Severity | Modified | minor => major |
17-Feb-2014 23:47 | BrianH | Status | Modified | submitted => built |
17-Feb-2014 23:47 | BrianH | Fixedin | Modified | => r3 master |
17-Feb-2014 23:47 | BrianH | Code | Modified | - |
17-Feb-2014 23:47 | BrianH | Description | Modified | - |
17-Feb-2014 23:47 | BrianH | Summary | Modified | Have TO LOGIC! 0 return true; remove TRUE?. => Have TO LOGIC! 0 return true |
18-Sep-2013 02:44 | Fork | Comment : 0003983 | Added | - |
17-Sep-2013 21:44 | BrianH | Comment : 0003982 | Added | - |
17-Sep-2013 21:22 | abolka | Comment : 0003981 | Added | - |
17-Sep-2013 19:31 | Ladislav | Comment : 0003980 | Added | - |
17-Sep-2013 19:03 | BrianH | Comment : 0003979 | Added | - |
17-Sep-2013 13:13 | Ladislav | Comment : 0003978 | Added | - |
16-Sep-2013 21:03 | BrianH | Comment : 0003974 | Added | - |
16-Sep-2013 20:22 | Ladislav | Comment : 0003973 | Modified | - |
16-Sep-2013 20:20 | Ladislav | Comment : 0003973 | Added | - |
16-Sep-2013 20:16 | Ladislav | Comment : 0003972 | Added | - |
16-Sep-2013 20:00 | BrianH | Ticket | Added | - |