World: r3wp
[Core] Discuss core issues
older newer | first last |
Graham 5-Apr-2008 [10177] | 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. |
Anton 10-Apr-2008 [10219x2] | Paul, you need to do something like this: parse a compose [set (first second :f ) integer!] where f is a function, second :f gives you the function's body, and FIRST picks a local word which just happens to be in first position in the body block. You will have to change FIRST to whatever navigates to a local word. |
Example, given a function: f: func [var][ print var: 10 ] then you will navigate to the 'var: set-word in the function body like so: second second :f because 'var: is in second position, after the 'print word. (it doesn't matter that it's a set-word and not a word, you can still set it and bind to it, etc) We can test this: set second second :f 20 get second second :f ; == 20 ?? f f: func [var][ print var: 10 ] Notice the 10 value is still the same (we didn't touch it.) But we know the 'var: set-word is 20 thanks to our setting it above. If the function is now evaluated it will not stay that way, obviously. | |
BrianH 11-Apr-2008 [10221x3] | Keep in mind that the words local to a function's context are only really valid during the execution of the function. When referred to from outside the function, their bindings are valid but their assigned values are not, and will be overridden on next run. |
This is even more the case in R3. | |
Much of the code in Ladislav's article wouldn't work in R3, because of the changes in functions and the different reflective accessors. | |
[unknown: 5] 11-Apr-2008 [10224] | thanks Anton, I had tried that but I want to do something a bit differently. I want to set a functions /local word instead of its arguments. |
Anton 12-Apr-2008 [10225] | It's the same method; all of the words (including the /local refinement) in the following function spec are local to the function's context: func [arg /local var] |
[unknown: 5] 12-Apr-2008 [10226] | I tried it Anton and it didn't work. I'm trying from within the same function. |
older newer | first last |