World: r3wp
[Core] Discuss core issues
older newer | first last |
Henrik 18-Jun-2008 [10654] | I would love to see it in R3, but so far nothing from Carl WRT this particular feature. I think it might complicate op! way too much. |
[unknown: 5] 18-Jun-2008 [10655x7] | I'm sure we can do something in the mezz sense once R3 gets released. |
Shouldn't < > and = return as a logic values as well as being op values? | |
>> logic? get to-word "<" == false >> | |
I guess because it doesn't return true or false until it operates on something it wont return a logic value. But maybe we should at least subclassify some operators to distingish them more. | |
some modifications made: | |
op+: func [blk /local op args arg blk2 blk3][ op: first back back tail blk blk3: copy [] arg: last blk if word? :arg [arg: get :arg] args: copy/part blk find blk op blk2: reduce [op arg] foreach item args [ insert blk2 item if item: attempt [do blk2][ either find form blk charset "<>=" [return item][append blk3 item] ] remove blk2 ] if not empty? blk3 [return blk3] false ] | |
>> op+ [1 2 3 4 + 1] == [2 3 4 5] | |
Henrik 18-Jun-2008 [10662] | what you return is that the datatype is op!, not logic!, so logic? returns false. |
[unknown: 5] 18-Jun-2008 [10663x4] | >> op+ [1 2 3 4 > 2] == true |
yeah I know I thought it would return logic and op depending on the test. | |
would be nice to have lop? | |
lop? - returns true or false if operator returns logic values. | |
Henrik 18-Jun-2008 [10667x2] | what do you mean? |
ok | |
[unknown: 5] 18-Jun-2008 [10669] | lop? would be a function |
Henrik 18-Jun-2008 [10670] | well, you wouldn't know without running actual tests with the operator. |
[unknown: 5] 18-Jun-2008 [10671x2] | yeah you can |
just like I do in the function above that I wrote. | |
Henrik 18-Jun-2008 [10673] | please explain, because I can't see where you do that. :-) |
[unknown: 5] 18-Jun-2008 [10674x4] | I'm just checking the charset |
all the ones that return logic are those operators that are or have in their form the characters "<" ">" or "=" | |
lop?: func ['op][if find form op charset "<>=" [return true] false] | |
>> lop? + == false >> lop? < == true | |
Henrik 18-Jun-2008 [10678] | I see. |
[unknown: 5] 18-Jun-2008 [10679x3] | seems handy to me. |
could be modified to become a true mezz | |
;a bit revised: lop?: func ['op][if all [op? get op find form op charset "<>="] [return true] false] | |
Gregg 18-Jun-2008 [10682] | You can sort of trick your way around things with ops in most cases. e.g. >> fn: func ['op a b] [op: get op op a b] >> fn < 1 2 == true But I avoid doing that. It ends up not being worth it, IMO, when you start to reuse things, generate code, etc. Just use func alternatives. |
[unknown: 5] 18-Jun-2008 [10683] | heh but cool Gregg. |
Chris 19-Jun-2008 [10684x2] | ; Here's a thought: any-where: func [series [block!] test [block!]][ foreach value series compose [if (test) [break/return value]] ] probe any-where [1 2 3 4][value > 4] probe any-where [1 2 3 4][value >= 4] probe any-where [1 2 3 4][value < 4] ; I know it's a two block solution, but it's pretty language friendly. You can recycle tests too: test: [value > 4] probe [1 2 3 4] :test probe [5 6 7 8] :test |
Oops, forgot the function at the end there... | |
[unknown: 5] 19-Jun-2008 [10686] | Very nice Chris! |
Anton 20-Jun-2008 [10687] | It's kind of like an "apply-any". |
Henrik 21-Jun-2008 [10688] | simple problem: >> a: [1 2 3 4 5] == [1 2 3 4 5] >> b: at a 3 == [3 4 5] >> a == [1 2 3 4 5] >> b == [3 4 5] >> remove a == [2 3 4 5] >> b == [4 5] ; I wonder if it's possible to make the index "sticky" at [3 4 5] in a relatively simple way. If it were, that would be very cool. |
Graham 21-Jun-2008 [10689] | copy it first! :) |
Henrik 21-Jun-2008 [10690] | nope, it has to be the same series |
Graham 21-Jun-2008 [10691] | and if you copy the index? as well? |
Henrik 21-Jun-2008 [10692] | it must be the same series |
Chris 21-Jun-2008 [10693] | Unless this is a feature request, you'll need an alternative to remove... |
Henrik 21-Jun-2008 [10694] | half a feature request and half trying to find a quick way to solve it. seems there is not an easy way. |
[unknown: 5] 21-Jun-2008 [10695] | can you just get around the problem by setting a: next a ? |
Henrik 21-Jun-2008 [10696] | yes. that's janitoring of the index, which could be prone to bugs, etc. |
[unknown: 5] 21-Jun-2008 [10697] | yeah you'll definately have to be more judicial with your code but I'm thinking that the mechanics of it is the way it is intended to operate. |
Henrik 21-Jun-2008 [10698x2] | yes, it is. it would be too hard to track from inside rebol when an index should move. |
(but if it were possible, some code would be greatly simplified) | |
Dockimbel 21-Jun-2008 [10700] | >> a: make list! [1 2 3 4 5] == make list! [1 2 3 4 5] >> b: at a 3 == make list! [3 4 5] >> a == make list! [1 2 3 4 5] >> b == make list! [3 4 5] >> remove a == make list! [2 3 4 5] >> b == make list! [3 4 5] |
[unknown: 5] 21-Jun-2008 [10701x3] | Let's talk memory... |
I that in the following the 10 represents 10 "bytes"? a: make string! 10 | |
So how to we define those things in a block? | |
older newer | first last |