World: r3wp
[Core] Discuss core issues
older newer | first last |
Graham 21-Aug-2009 [14522] | graham- findall "this is a test string" [ "this" "not here" ] == none |
Geomol 21-Aug-2009 [14523x2] | I guess joint is commonly used for marijuana LOL, I didn't see that! (And I went to a Reggae festival last week, so I should know.) :-) |
Do you want your function to find "ring" in this string: "this is a test string"? | |
Graham 21-Aug-2009 [14525] | yes |
Sunanda 21-Aug-2009 [14526] | Geomol -- your code works only if the blocks are sorted, and contain no duplicates: findall [5 4 3 3 2 1] [3 2 1 1] == false One way to fix that: findall: func [s items [block!]] [0 = length? exclude items intersect s items] findall [5 4 3 3 2 1] [3 2 1 1] == true But it does not help much with Graham's example which is looking for substrings :( |
Geomol 21-Aug-2009 [14527] | What about this version? findall: func [s items [block!]] [foreach i items [if not find s i [return false]] true] |
Graham 21-Aug-2009 [14528x2] | I thought with map you can apply a function over all the parameters ... |
looks good | |
Geomol 21-Aug-2009 [14530x3] | Yes, you can with map, but you want it to stop, if one item isn't found, so not on all parameters. |
Chris wrote: "G: re. confused - try stepping through the function in the order it is interpreted. Should be clear by the time 'use evaluates the two blocks..." What I find a bit confusing is, when I have to BIND and when I don't. It's the context binding rules in REBOL, that is not 100% clear to me. Let me give a simple example: >> b: [print i] == [print i] >> f: has [i] [i: 1 do b] >> f ** Script Error: i has no value This doesn't work, because the b block is defined outside the f function, outside f's function context. Therefore I have to bind b to f's context, like this: >> f: has [i] [i: 1 bind b 'i do b] >> f 1 That is clear, and I would expect USE to work by the same rules, but it doesn't quite, it seems to me: >> f: does [use [i] [i: 1 do b]] >> f 1 By some magic, this works without the need to BIND. I'm a bit confused by that. | |
ARGH! It only works, because I first made the f function using BIND. So b was already bound to f, when I changed f to include USE. If I try to USE version from a fresh REBOL, it doesn't work. (More confusion!) :-p | |
Anton 21-Aug-2009 [14533x2] | Graham, I think your FINDALL is not well named. Just because it's using FIND doesn't mean it's doing the same thing. It should be more like COLLECT-ALL or COLLECT-EVERY. |
Sorry, I'm wrong. Wrote too quickly. | |
Geomol 21-Aug-2009 [14535] | Ok, from a freshly started REBOL, this doesn't work: >> b: [print i] == [print i] >> f: does [use [i] [i: 1 do b]] >> f ** Script Error: i has no value But this does work: >> b: [print i] == [print i] >> f: does [use [i] reduce [to set-word! 'i 1 'do b]] >> f 1 Is it because, when b is reduced, I kinda get a new fresh copy of the block? Like if I wrote the block, [print i], myself instead of using a reference to b? |
Anton 21-Aug-2009 [14536] | REDUCE makes a new block, and then USE does its binding. |
Geomol 21-Aug-2009 [14537] | Oki doki, that explains it. |
Anton 21-Aug-2009 [14538x2] | BIND recurses into blocks, eg. 'b will be bound in the nested block [[b]], but if 'b happens to currently have a value that is a block with words in it, that doesn't matter to BIND, BIND won't go in there. |
Let me say that again, to be clear. eg. Binding [[b]] somewhere will cause 'b to be bound (as long as 'b exists in the "somewhere" context). but if, before this bind occurs, b has a block value eg. b: [some words] , then the bind will not touch 'some and 'words, because it won't look to recurse into word values that happen to be blocks. | |
Geomol 22-Aug-2009 [14540] | How to check for a datatype using TYPE? within a function in REBOL 2? Let's say, I wanted to create my own ACTION? function using TYPE?: >> a?: func [value] [action! = type? value] >> a? :action? == false Doesn't work. Does the logic work outside a function? >> action! = type? :action? == true Yes. So maybe I need to specify the argument as a get-word! ? >> a?: func [:value] [action! = type? value] >> a? action? == false No, still doesn't work. Now on to REBOL 3 to see, how that work: >> a?: func [value] [action! = type? value] >> a? :action? ** Script error: value is missing its value argument Huh? Trying with a get-word! : >> a?: func [:value] [action! = type? value] >> a? action? == false No, doesn't work. What am I missing? Or is it bugs? |
Anton 22-Aug-2009 [14541] | Try this in the console: >> action? == false No arguments were provided. The function can accept unset! values. |
Geomol 22-Aug-2009 [14542x2] | Anyone got an old REBOL 1 lying around, I could have a look at? |
Anton, ah, but my function doesn't work with other action! values anyway: >> a?: func [:value] [action! = type? value] >> a? first ** Script Error: value expected series argument of type: series pair event money date objec t port time tuple any-function library struct ... Trying dobble get-word! : >> a? :first == false So maybe this doesn't work with any action! datatype? | |
Anton 22-Aug-2009 [14544x2] | It looks like your a? function evaluated the argument 'value. (I forget what get-word function parameters do...) Works better like this: a?: func [value][action! = type? :value] |
Better is a?: func [value][action? :value] | |
Geomol 22-Aug-2009 [14546x4] | >> a?: func [value] [action! = type? :value] >> a? :action? == true Bravo! |
My mistake. I get it now! | |
Thanks! | |
Anyone got an old REBOL 1 lying around, I could have a look at? | |
Anton 22-Aug-2009 [14550] | I noticed a get-word parameter prevents a paren argument value being evaluated first. >> f: func [a][print mold a] >> f (action?) false >> f: func [:a][print mold a] >> f (action?) (action?) |
Geomol 22-Aug-2009 [14551x5] | Yeah, and you would probably like it to be mold :a in the function to not do the same mistake, I did. In your first example, you have evaluation of a two times, first as (action?) leading to false, and then false is evaluated when doing mold a. |
Hey, I just read all that again. I can't figure out, why your second example returns (action?). That parenthesis should be evaluated, when you write mold a, shouldn't it? | |
It's the same in R3. | |
On the other hand, with the current behaviour, paren! works as block! in such situations. Blocks are not evaluated, when we write mold a, and a is a block. So why should a, if a is a paren! ? :-) | |
>> p: to paren! [a b c] == (a b c) >> mold p == "(a b c)" That's ok, I think. | |
Maxim 22-Aug-2009 [14556x2] | yep, we need that in order to handle things like parens in dialects. |
>> a: [1 2 (3 4)] == [1 2 (3 4)] >> third a == (3 4) | |
Ladislav 23-Aug-2009 [14558] | Geomol, I think, that you missed http://en.wikibooks.org/wiki/REBOL_Programming/Advanced/Interpreter |
Geomol 23-Aug-2009 [14559] | Ladislav, how did you get the info to write that? |
Ladislav 24-Aug-2009 [14560] | tests/experiments |
Graham 25-Aug-2009 [14561x2] | Given some Json data like this:: { page :"1","total":4,"records":"22", rows :[{"id":null,"cell":["Quantum of Solace","Marc Forster","2008","Daniel Craig","200"]}, {"id":null,"cell":["Casino Royale","Martin Campbell","2006","Daniel Craig","150"]}, {"id":null,"cell":["Die Another Day","Lee Tamahori","2002","Pierce Brosnan","142"]}, {"id":null,"cell":["The World is Not Enough","Michael Apted","1999","Pierce Brosnan","135"]}, {"id":null,"cell":["Tomorrow Never Dies","Roger Spottiswoode","1997","Pierce Brosnan","110"]}, {"id":null,"cell":["GoldenEye","Martin Campbell","1995","Pierce Brosnan","58"]}, {"id":null,"cell":["Licence to Kill","John Glen","1989","Timothy Dalton","36"]}] } using Rebol-to-json, what sort of Rebol data object do I need to create to produce that output? |
I've tried various combinations of objects and blocks and usually the rebol-to-json function just breaks. | |
Maxim 27-Aug-2009 [14563] | I am beyond mystified! what is wrong with this code? (1.3 * (any [rgb clr])) both rgb and clr have tuple values... if I remove the any, it works, if I try the any and probe it, it returns the proper value... this is within a compose block. ** Script Error: Cannot use multiply on decimal! value ** Where: refresh-gfx ** Near: 1.3 * (any [rgb clr]) |
PeterWood 27-Aug-2009 [14564x2] | Try reversing the operands to the *. It seems to work: >> clr: 0.0.0 == 0.0.0 >> rgb: 4.4.4 == 4.4.4 >> 1.3 * (any [rgb clr]) ** Script Error: Cannot use multiply on decimal! value ** Near: 1.3 * (any [rgb clr]) >> ((any [rgb clr]) * 1.3) == 5.5.5 |
Haven't figured out why :-) | |
Maxim 27-Aug-2009 [14566x2] | I can almost swear I tried it! but anyhow I did the 'ANY earlier in the code.... and just use rgb directly now... |
thanks for the help though... this is a really strange bug :-) | |
Sunanda 27-Aug-2009 [14568] | R2 does not allow [decimal! * tuple!] but it does allow [tuple! * decimal!] with a tuple! as the result 1.3 * 9.9.9 ** Script Error: Cannot use multiply on decimal! value 9.9.9 * 1.3 == 11.11.11 R3 allows both, with a tuple! as a result. Looks like an R2 bug fixed only in R3. |
Graham 27-Aug-2009 [14569x3] | In forming iso-8601 dates , you need to add the sign of the time zone. Would you believe that pick [ "+" "-" ] positive? now/zone is 4x faster than this either (1 = (sign? now/zone)) ["+"] ["-"] |
It relies on the behaviour of pick using false is same as pick 2 | |
Is that going to be the same in R3? | |
older newer | first last |