World: r3wp
[Core] Discuss core issues
older newer | first last |
btiffin 5-Apr-2008 [10169x2] | remove-each |
Or while? | |
Graham 5-Apr-2008 [10171x4] | cool |
how's this >> date: "* 10 May, 2008" == "* 10 May, 2008" >> d: parse date none == ["*" "10" "May" "2008"] >> remove-each b d [ not any [ parse b alphas parse b digits ] ] == ["10" "May" "2008"] >> d: to-block form d == [10 May 2008] | |
I'm trying to clean up OCR'd text prior to parsing | |
to end up only with integers and alphas ... is this bullet proof? | |
Henrik 5-Apr-2008 [10175] | >> to-block "3a" ** Syntax Error: Invalid integer -- 3a Not entirely... |
Graham 5-Apr-2008 [10176x2] | it won't pass my parse rule |
I parse digits and chars separately .. I'm not using an alphanumeric parse | |
Henrik 5-Apr-2008 [10178] | ok, if that's the case, you should be fine. |
btiffin 5-Apr-2008 [10179] | Yeah I'm playing too ... |
Graham 5-Apr-2008 [10180] | I'm sure the parse gurus can do this all in one parse rule! |
btiffin 5-Apr-2008 [10181x2] | I wanna junk! datatype ... parsed (made / loaded) up to next space during interpret. Then we could read scripts modified by normal people. Might be a lot of junk! but I'd rather write a junk! handler than try and trick REBOL. |
read = load | |
Graham 5-Apr-2008 [10183x2] | yeah ... that would be neat. |
I'd call it crap! though | |
Anton 6-Apr-2008 [10185x4] | date: "* 10 May, 2008" allowed: union union alpha digit charset " " parse remove-each char date [not find allowed char] none == ["10" "May" "2008"] |
but you got a problem with this date: "10 May,2008" ---> ["10" "May2008"] | |
date: "10 May,2008" parse replace/all date complement allowed " " = ["10" "May" "2008"] date: "* 10 May, 2008" parse replace/all date complement allowed " " == ["10" "May" "2008"] | |
which passes a charset to to REPLACE. | |
Henrik 9-Apr-2008 [10189x2] | >> a: [(i)] == [(i)] >> repeat i 5 [print i compose a] 1 ** Script Error: i has no value ** Where: halt-view ** Near: i >> repeat i 5 [print i compose load mold/all a] 1 ** Script Error: i has no value ** Where: halt-view ** Near: i Is that correct? I'm obviously missing something, but I don't know what. Does COMPOSE not work inside the REPEAT context? >> b: ['i] == ['i] >> repeat i 5 [print i reduce b] 1 2 3 4 5 == [i] This works as expected. |
solved it: >> a: [(i)] >> repeat i 5 [print i compose bind a 'i] 1 2 3 4 5 == [5] I assumed that LOAD MOLD/ALL would kill the existing bindings and re-bind it to whatever context it was being run in. I guess it doesn't do that. | |
Anton 9-Apr-2008 [10191] | I think LOAD just binds to global context. |
Henrik 9-Apr-2008 [10192] | yes, I think it does. |
Geomol 9-Apr-2008 [10193] | :-/ Yeah, that must be the answer. Do we need a /local (or something) refinement for LOAD? |
Anton 9-Apr-2008 [10194x2] | c: context [print: "local" w: load "print"] type? get c/w ; == native! |
Geomol, why add another refinement when you can just use BIND, which allows you to bind it anywhere ? | |
Geomol 9-Apr-2008 [10196x2] | Yes, LOAD is native. !? What's the point? |
Anton, right. Good point. | |
Anton 9-Apr-2008 [10198] | And in any case, what does "local" mean ? How would LOAD determine what is meant by local ? The block it's in does not have any associated context. |
Geomol 9-Apr-2008 [10199] | Ah, let me reconsider the native! thing. Was thinking in terms of blocks. It's an object! of course. ... |
Anton 9-Apr-2008 [10200] | Only the words in the block know what context they're bound to. |
Geomol 9-Apr-2008 [10201x2] | >> probe get a/w native |
Heh! :-) I'm not so sharp today. | |
Anton 9-Apr-2008 [10203] | In the code above, I make an object which has a local word 'print (with a local value "local"), and another word 'w whose value is LOADed from the string "print" (which becomes the word 'print). This new word is bound to the global context. Where else could it be bound ? The word 'load in the block above is not bound to the context I made, it retains its global binding (which is why it actually does what we expect it to). |
Geomol 9-Apr-2008 [10204] | I was doing this: a: context [w: load "print"] get a/w Same thing. I understand you now, Anton. The words know, what context they're bound to. So it should all just be sorted out with BIND. And BIND can be confusing (at leat I find it confusing now and then). |
Anton 9-Apr-2008 [10205] | Yes, the "invisible links" of bind can be confusing. |
Geomol 9-Apr-2008 [10206] | Thanks for the explanation! :-) |
Anton 9-Apr-2008 [10207] | np |
Geomol 9-Apr-2008 [10208x4] | And we can make our own LOAD to do, what we want: :-) >> c: context [print: "local" load: func [w] [bind to block! w self w] w: load "print"] >> type? c/w == string! >> c/w == "print" |
Argh, that should return "local", shouldn't it? :-D | |
BIND is hard! Period! ;-) | |
This does it (I think): >> c: context [print: "local" load: func [w] [first reduce bind to block! w self] w: load "print"] >> c/w == "local" | |
[unknown: 5] 9-Apr-2008 [10212x4] | Maybe someone will know if this is possible. I want to be able to set a value when parsing outside a function to a local value in context of a funciton. I can do this with an object but want to know how to do it with a function. Here is the object method: |
a: [1] b: context [c: none] parse a compose [set (in b 'c) integer!] | |
>> b/c == 1 | |
I want to be able to instead of having b as an object be able to have b as: b: func [val /local s][print val + s] where I want to set 's from the parsing. | |
Geomol 9-Apr-2008 [10216] | I found, that making my own version of LOAD in a context in another way worked: >> c: context [print: "local" my-load: :load w: my-load print] >> c/w == local >> type? c/w == word! But it doesn't work as Henrik would like in a REPEAT block: >> a: [(i)] == [(i)] >> repeat i 5 [print i my-load: :load compose my-load mold/all a] 1 ** Script Error: i has no value |
btiffin 9-Apr-2008 [10217] | Paul; you've read through the Ladislav articles? tfunc and lfunc and his Bindology paper? http://www.fm.tul.cz/~ladislav/rebol/ |
[unknown: 5] 9-Apr-2008 [10218] | I have read a lot of his stuff but not sure I ever read this. I'll take a look into it. Thanks Brian. |
older newer | first last |