-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have TO LOGIC! 0 return true #2055
Comments
Submitted by: Ladislav I support this idea, since I never needed TO LOGIC! 0 to return FALSE. |
Submitted by: Ladislav 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. |
Submitted by: BrianH 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. |
Submitted by: Ladislav Just a remainder: >> make logic! 0
== false >> make logic! 1
== true |
Submitted by: BrianH Well, that means we won't have lost functionality. Unless you want to change MAKE too? |
Submitted by: abolka 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!. |
Submitted by: BrianH TRUE? could be another word for TO-LOGIC, and both could be optional, not included in minimal builds. Just like FOUND?. |
Submitted by: fork 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 |
Submitted by: BrianH
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.
CC - Data [ Version: r3 master Type: Wish Platform: All Category: Datatype Reproduce: Always Fixed-in:r3 master ]
The text was updated successfully, but these errors were encountered: