World: r3wp
[Core] Discuss core issues
older newer | first last |
[unknown: 5] 1-Sep-2007 [8685] | shouldn't poke work on port data if pick does? Seems strange behavior for it not to |
Gabriele 2-Sep-2007 [8686x2] | i'd actually suggest retry [f1] 4 or retry [f2] 4 with my code. :f also works but if f takes arguments it would break. so it's cleaner to just always use a block. |
actually, there is one problem with return, which is if you want to do retry [... return 'something ...] and have it return from the calling function, not retry (like if cond [return 'something]). to allow that, you need to add the [throw] func attribute, ie. retry: func [[throw] code times] ... | |
DanielSz 2-Sep-2007 [8688x2] | Thanks for the advice, Gabriele, I'll play around with it for a while... |
Gabriele, I'm trying to understand in what kind of situation a throw is required. f1: func [] [if true [return "something"]] works without a throw, for example. Can you provide a concrete example of code that requires the throw attribute to 'retry? Thanks! | |
Gabriele 3-Sep-2007 [8690x3] | i'm not sure it is needed or not for retry. it depends on how you use it. |
f: func [] [ retry [ ; do something... if cond [return something-else] ; ... ] some-val ] | |
if you want the return inside retry to return from F and not RETRY, then you need [throw]. | |
DanielSz 3-Sep-2007 [8693] | Thanks, Gabriele, I haven't thought about that. |
Joe 4-Sep-2007 [8694x3] | is the sort block dialect broken ? |
b-test: ["xxx" "V" 4 "xxx" "M" 3 "yyy" "Laaaa" 2 "yyy" "Lbbbb" 2 "yyy" "Kaaaa " 2 "yyy" "Haaaa" 2 "yyy" "Aaaaa" 2] print ["init " mold b-test] sort/skip/compare b-test 3 [reverse 3 2] print ["reverse 3 2 " mold b-test] sort/skip/compare b-test 3 [reverse 3 reverse 2] print ["reverse 3 reverse 2" mold b-test] | |
It seems to use the first reverse 3 but ignore the second comparator. Any ideas ? | |
btiffin 4-Sep-2007 [8697x2] | Joe; I think you need to pass sort/compare a function! not a block! The function template is [a b] and returns true or false or whether to swap. Something like sort/compare data func [a b] [a > b] (Note: the names a and b could be any words but the function is called with two arguments). |
Never mind my blabbering. Learned something new today. :) | |
Graham 5-Sep-2007 [8699] | Can someone remind me how bind a bunch of words to a different context? I want to use the named colors in a special context. |
Chris 6-Sep-2007 [8700] | colors: context [red: 255.0.0 green: 0.255.0 blue: 0.0.255] reduce bind [red green blue] in colors 'self |
Graham 6-Sep-2007 [8701] | I'll give it a go :) |
[unknown: 5] 6-Sep-2007 [8702] | anyone know if REBOL runs on PocketPC? |
Graham 6-Sep-2007 [8703x2] | core used to ... |
wince 1.1 ? | |
james_nak 6-Sep-2007 [8705] | I don't know if the CE version does but: http://www.rebol.com/platforms-core.html (Note: these are oldies but goodies) |
btiffin 7-Sep-2007 [8706] | Graham; To quickly get all the colours, try rebol [] do-thru http://www.rebol.org/library/scripts/capture.rcapture on help tuple! capture off colors: copy [] parse to block! find get-captured newline [ some [set col word! (append colors col) word! tuple!] ] ;; This will fail, no context print disarm try [get first colors] ;; Now bind the words to the REBOL context bind colors 'red print get first colors |
Gregg 10-Sep-2007 [8707] | Joe, did you try "[reverse 3 forward 2]" as your comparator? |
btiffin 11-Sep-2007 [8708] | Request for opinions; What would you rather read? var: none ... var: either flag [value] [none] or var: if flag [value] Assuming var can safely be none or a value but the init may not be close to the code. |
Graham 12-Sep-2007 [8709x2] | var: pick [ value ] flag |
was I allowed that option?? | |
btiffin 12-Sep-2007 [8711] | Certainly, but that would not bounce out at me during a quick grok...perhaps with exposure. |
Chris 12-Sep-2007 [8712] | var: all [flag value] |
Gregg 12-Sep-2007 [8713] | I favor EITHER or ALL for this, in general. |
Izkata 12-Sep-2007 [8714] | I'd go with the 'either or the 'if |
Graham 12-Sep-2007 [8715] | Forth does it the pick way to avoid using logic |
Ashley 12-Sep-2007 [8716] | 'all is faster than 'if or 'either ... also more "extensible" in that it scales, as in: var: all [flag1 flag2 flag3 value] var: any [flag1 flag2 flag3 value] |
btiffin 12-Sep-2007 [8717x2] | Thanks for the opinions gentlemen. All over the map of course. But Gregg's matters most, so either it is. :) And I've found the either to be the easier grok when quick scanning, no double think required. This is not in tight code, so readability wins over performance concerns. And just an aside; all [false false] returning none...kinda sucks. all [none none] returning none, sure; but all [false true] should be false, not none. Or change the help doc to ...and returns NONE at the first FALSE or NONE. Well, it doesn't suck persay, it just doesn't behave as the help would suggest. |
Oh, now Ashley fills in more of the picture as I was typing. Seeing as I can use either or all, perhaps I'll start getting used to all for this idiom. :) | |
Chris 13-Sep-2007 [8719x2] | It's like 'if in that regard though. 'if returns none when the condition is false... |
I guess 'all could be considered "all or nothing". | |
btiffin 13-Sep-2007 [8721] | Yeah, I was just griping about docs. :) none is fair return, and consistent for all cases, pun intended. |
Henrik 13-Sep-2007 [8722] | this is spinning my brain: foreach [a b] [1 2 3 4] [print get load "a"] ** Script error: a has no value How do I bring "a" under the correct context? |
Gregg 13-Sep-2007 [8723] | foreach [a b] [1 2 3 4] [print get bind load "a" 'b] |
Henrik 13-Sep-2007 [8724] | gregg, thanks, it works :-) |
Joe 13-Sep-2007 [8725] | Gregg, thanks, forward worked ! It's hard to know without documentation. How did you know ? |
Gregg 14-Sep-2007 [8726] | Joe, Sorry, I thought you must have found the docs, since you got as far as you did. :-) http://www.rebol.com/docs/core25.html#sect4.1.4. |
james_nak 14-Sep-2007 [8727] | How do you clear out a local variable within a function? I have this scenario and I can't get the function to run more than once. I could copy the contents to a temp var but that seems silly. a: func [ some-var /local s] [ s: "example %text% string" replace/all s "%text%" some-var ] Once I run this thing "s" never gets its orginal value. Thanks |
Alberto 14-Sep-2007 [8728] | s: copy "example %text% string" |
james_nak 14-Sep-2007 [8729] | So simple. Thanks Alberto. Estas en Mexico? |
Alberto 14-Sep-2007 [8730] | así es |
james_nak 14-Sep-2007 [8731] | DF? |
Alberto 14-Sep-2007 [8732x2] | sí, en el DF |
tu dónde estás? | |
james_nak 14-Sep-2007 [8734] | Estoy en California acerca de Los Angeles. |
older newer | first last |