World: r3wp
[Core] Discuss core issues
older newer | first last |
Fork 1-Apr-2008 [9942] | Dockimbel: you seem to be right. I wonder what happened when I tried it at first? |
[unknown: 5] 1-Apr-2008 [9943x2] | Just make sure Fork that when you work with series data and checking for length of the entire series that your at the head of the series. You can do that by the following: length? series: head series |
That is especially important when working with list! datatype | |
Fork 1-Apr-2008 [9945x2] | Is it considered good practice to treat "none" as a false in a conditional expression? I find that a little confusing, e.g. either find list value [truecondition] [falsecondition] ... what if "false" is an element in the list? |
Hm, or for that matter, what if none is? | |
[unknown: 5] 1-Apr-2008 [9947x2] | None! is not the same as false |
Here is would be the difference Fork: >> found? false == true >> found? none == false | |
Fork 1-Apr-2008 [9949] | Ah, I see find returns a series, not a word. Got it. |
[unknown: 5] 1-Apr-2008 [9950] | yes |
Fork 1-Apr-2008 [9951] | I'm trying to wrap my head around the situation I'm concerned about but don't know quite how to say it, but it's something like: if [first find [false true] 'false] [print "False is the first element"] |
[unknown: 5] 1-Apr-2008 [9952] | >> if first find [false true] 'false [print "false is the first element"] false is the first element |
Fork 1-Apr-2008 [9953] | >> probe 1 = 0 false == false >> probe first find [false true] 'false false == false |
[unknown: 5] 1-Apr-2008 [9954] | >> pick [true "false is the element"] false == "false is the element" |
Dockimbel 1-Apr-2008 [9955] | >> type? probe 1 = 0 false == logic! >> type? probe first find [false true] 'false false == word! |
[unknown: 5] 1-Apr-2008 [9956] | Fork the false is being returned because it is the last value. |
Fork 1-Apr-2008 [9957] | >> (1 = 0) = (first find [false true] 'false) == false |
Dockimbel 1-Apr-2008 [9958] | in [false true], both are word! values, not logic!. If you want logic! values : logic! = first find reduce [false true] false |
Fork 1-Apr-2008 [9959x3] | >> (1 = 0) = (first find reduce [false true] false) == true |
A ha | |
Is there a version of probe that prints the type also? | |
Dockimbel 1-Apr-2008 [9962] | Not by default, but here's one : probe*: func [value][probe :value probe type? :value :value] |
Fork 1-Apr-2008 [9963x3] | Dockimbel: very useful! |
>> if 'hedgehog [print "hedgehog"] hedgehog | |
Oh my. Well, I think I'd rather define a "safe" if that only accepts true/false if there isn't such a thing | |
Dockimbel 1-Apr-2008 [9966x2] | In REBOL everything is TRUE except false and none! values. |
Btw, " favorite_fruit/set-value 'banana " doesn't look very rebolish to me...IMHO, REBOL way would be more like : " set-enum favorite_fruit 'banana ". When you MAKE an object! in REBOL, all its functions are duplicated, so keeping the functions inside an object! and using it as in a class/instances model ends up eating a lot of memory. That's why the more "rebolish" way, where the code is out of the objects, is the way to go if you deal with a lot of instances (which might be the case for a "class" like enum!). Remember that REBOL objects are prototype-based, meaning that they are created by cloning, not by instantiating a class. R3 will maybe bring us true class! datatype or at least a clean way to implement it by ourselves. | |
Geomol 1-Apr-2008 [9968] | To check, if false is the first element: >> if head? find [false true] 'false [print "false is the first element"] false is the first element >> if head? find [true false] 'false [print "false is the first element"] == none |
Fork 1-Apr-2008 [9969x2] | Geomol: good point... that wasn't what I was doing, the quote should have been "false is in the list" :) |
Dockimbel: That's quite good to know, thank you, I will make that change. | |
Geomol 1-Apr-2008 [9971x2] | It was a quick ping-pong up there, so I'm not sure, if you know the answer, but to find false in a series: >> if find [false true] 'false [print "false is in the list"] false is in the list And you know, this isn't the value FALSE, it's just words. |
To check for the logic! value FALSE, you have to reduce the block: >> if find reduce [false true] false [print "The logic! value false is in the series"] The logic! value false is in the series >> if find reduce ['false true] false [print "The logic! value false is in the series"] == none | |
Fork 1-Apr-2008 [9973x3] | >> if ( reduce first find [false true] 'false ) [print "false is in the list"] false is in the list |
I'm looking for how to make first find [false true] 'false NOT print false is in the list | |
As per my usual question method, if y is ( reduce first find [false true] 'false )... what is f(y) to make that happen :) | |
Henrik 1-Apr-2008 [9976x2] | because FALSE there is a word!, not logic!. |
>> first find [false true] 'false == false >> type? reduce first find [false true] 'false == word! | |
Fork 1-Apr-2008 [9978] | That much I get, I just thought that reduce turned false-as-word into false-as-logic and it does not |
Geomol 1-Apr-2008 [9979] | Yes, it's still a word! and not a logic!, even if you reduce it. |
Fork 1-Apr-2008 [9980] | So what turns it into a logic, if not reduce? |
Dockimbel 1-Apr-2008 [9981] | do |
Henrik 1-Apr-2008 [9982] | reduce the block instead |
Fork 1-Apr-2008 [9983] | >> if ( do first find [false true] 'false ) [print "false is in the list"] == none |
Henrik 1-Apr-2008 [9984] | looks like R3 does not exhibit that behavior. it's reduced to logic! |
Fork 1-Apr-2008 [9985] | Ok, great, that's the case I was worried about then... |
Geomol 1-Apr-2008 [9986] | Or LOAD: >> load to string! 'false == false |
Fork 1-Apr-2008 [9987] | I'm confused as to why reduce, which seems to perform other evaluations, would not (in R2) turn false into a logic!... Henrik, you are saying it does? |
Henrik 1-Apr-2008 [9988] | Fork, Rebol 3 does, so this may be an inconsistency in Rebol 2. |
Geomol 1-Apr-2008 [9989x2] | It's often works, if you turn stuff into a string and then load that. Other ways to turn stuff into strings: >> load mold 'false == false >> load form 'false == false |
*It* often works ... | |
btiffin 1-Apr-2008 [9991] | Not quite; reduce 'false is a word, reduces as a word! reduce [false] reduces the block, evaluating false to the logic! false. It's fun stuff. ;) mold/all can be your friend exploring the ins and outs of evaluated values. |
older newer | first last |