World: r3wp
[Core] Discuss core issues
older newer | first last |
Brock 9-Oct-2008 [11054x2] | I'll take a look. Thanks. |
Hmm, after looking at this, I then have the reverse problem for the remainder of the code, it now doesn't get the value of the parameter that was passed. I'll need to play with this a while longer, but it looks like I'm heading in the right direction. Tx. | |
Dockimbel 9-Oct-2008 [11056] | >> name: "rebol" == "rebol" >> my-trim: func ['word][print [word ":" get word]] >> my-trim name name : rebol |
Gregg 9-Oct-2008 [11057] | I've gotten away from using lit-word params for the most part. Instead, I use the lit-word as the arg. my-trim: func [word] [print [word ":" get word]] my-trim 'name |
Will 9-Oct-2008 [11058] | why that Gregg? |
Terry 11-Oct-2008 [11059] | I knew this at one time, but is there a way to test if a word has been set / exists, that doesn't involve error trapping? >> if error? try [n][print "error"] error |
Graham 11-Oct-2008 [11060x2] | value? ''word |
'word | |
Terry 11-Oct-2008 [11062] | wasn't there an isset? function one time? |
Graham 11-Oct-2008 [11063] | php? |
Terry 11-Oct-2008 [11064x3] | hmm. .yeah |
:) | |
>> value? to-lit-word "monkey" == false >> isset?: func[str][value? to-lit-word str] == [value? to-lit-word str] >> isset? "monkey" == "monkey" ?? | |
Pekr 11-Oct-2008 [11067] | >> isset?: func[str][value? to-lit-word str] >> isset? "monkey" == false |
Terry 11-Oct-2008 [11068] | hmm.. working here now too. must have messed up the function somehow. |
Graham 11-Oct-2008 [11069] | >> isset?: :value? >> isset? 'test == false >> isset? 'rebol == true |
Henrik 11-Oct-2008 [11070] | don't you have to be careful with the binding when doing value? to-word "something" ? |
Terry 11-Oct-2008 [11071] | Im using it to check a parsed block to see if the value is set.. is there a better way? |
Claude 11-Oct-2008 [11072x2] | hi, i would like to know how to open a port with rebol in FTP to connect a ISERIES or IBM I or AS400 and execute commande like this on "quote namemft 1" or "cd /" or "quote syscmd call a PGM" |
i would like to do it like in dos windows that the FTP command can take a file as input and then execute all commands in that file | |
BrianH 11-Oct-2008 [11074x4] | If you do to-word "something" in R2 the word returned will be bound to the global context, so it will only have a value if a word of that name in the global context already has a value. It doesn't matter if you do to-word in a function. |
Terry, I have found that the best way to check if a value has been set to a word in a parse rule, the best way is to set the word to none before you run the parse rule (or at the beginning of the rule in a paren), then check to see if it is still none afterwards. | |
You can use NONE? to do that, or the checker for whatever datatype you are looking for if you want a positive result. The IF function also treats NONE as false, so if you are not looking for logic values you can use it directly. Like this: a: none parse [1 2 3] [set a integer!] ; will return false if a [ ; you found it, do something ] If you think the value you are testing might be an active value (like a function), refer to it with a get-word! for safety, like :a. | |
The none technique especially words for string parsing and the copy operation because it sets the word to none if there was an empty string copied, useful to know. | |
Graham 11-Oct-2008 [11078] | Claude you'll have to write your own ftp client |
Terry 11-Oct-2008 [11079x2] | Brian, that works fine, but now I need to set 200+ words to /local in my function? |
When doing a 'parse block', what's the best way to localize a couple hundred words for post parsing? | |
Chris 12-Oct-2008 [11081x2] | ; pre-process the parse block? -- localize: func [block /local word words rule][ words: copy [] rule: [set word any-word! (append words word) | into [any rule]] parse block [any rule] forall words [words/1: to-word words/1] use words compose/only [(block)] ] parse series localize rule |
Could be tidied up a little with an exceptions option... | |
Terry 12-Oct-2008 [11083] | can't seem to get it to fire.. do you have a working example by chance? |
Chris 12-Oct-2008 [11084x5] | >> parse "str" localize [a: "str" (probe b: a)] "str" == true >> a ** Script Error: a has no value ** Near: a >> b == "str" |
I guess 'into doesn't go into paren! in 2.7.6? | |
; perhaps I forgot something: localize: func [block /local word words rule][ words: copy [] rule: [set word any-word! (append words word) | into [any rule] | skip] parse block [any rule] forall words [words/1: to-word words/1] use words compose/only [(block)] ] | |
Anyhow, could use some work, just throwing out the idea... | |
localize: func [block /with except /local word words rule][ words: copy [] rule: [set word any-word! (append words word) | into [any rule] | skip] parse block [any rule] forall words [words/1: to-word words/1] words: difference unique union words except except use words compose/only [(block)] ] parse "string" localize/with [a: "str" (probe a) copy b "ing" (probe b)][probe] | |
Gabriele 13-Oct-2008 [11089] | Anton, yes, as Brian says, that looks like a bug. |
Anton 13-Oct-2008 [11090] | Well, I guess a bug report is due then. Who's responsibility is it ? Graham - I think you :) |
BrianH 13-Oct-2008 [11091] | Terry, you should consider structuring your parse rules so that you can do more processing of the data you recognize on the fly in parens. When you are using a hundred local words and doing your processing afterwards, you are repeating yourself. |
Gregg 13-Oct-2008 [11092] | Will, I got away from lit-word! params because they're a pain when you're doing more dynamic things in code. As soon as you want to compute the arg, they get in the way. My classic example is an INCR function. For control funcs, I think they make the calling code read more naturally, and the cases where they cause problems there are much less frequent. |
Davide 15-Oct-2008 [11093] | hi, I need your help with bind: - I have an object h h: make object! [ q: [] ] append h/q make object! [ f1: func [a][print ["f1" a]] f2: func [b][f1 join "f2 " b] ] if I call f1 and f2 the results are correct: >> h/q/1/f1 "hi" f1 hi >> h/q/1/f2 "hi" f1 f2 hi --------------------- Now, I want to make the code of f2 dynamic, so I add a second param "code" to f2: h/q/1/f2: func [b code][do code] of course this doesn't work, f1 and b aren't bound: >> h/q/1/f2 "hi" [f1 join "f2 " b] ** Script Error: f1 has no value ** Where: f2 ** Near: f1 join "f2 " b I've tried with no luck the followings: h/q/1/f2: func [b code][do bind code 'f2] h/q/1/f2: func [b code][do bind code in h/q/1 'f2] What is the magic word: "do bind code ******* " ? |
Anton 15-Oct-2008 [11094x3] | The 'f2 word which you are trying to use as an example word is not bound to the object you want, because you create the function after making the object. If you had defined the function which does the bind directly in the object spec to start with you wouldn't have this problem. But if you need to define the function after creating the object, then you could do any of these: |
h/q/1/f2: func [b code][do bind bind code 'b h/q/1] h/q/1/f2: func [b code][do bind bind code 'b in h/q/1 'self] h/q/1/f2: func [b code] compose [do bind bind code 'b (h/q/1)] h/q/1/f2: func [b code] compose [do bind bind code 'b (to-lit-word in h/q/1 'self)] h/q/1/f2: func [b code] compose [do bind bind code 'b (to-lit-word in h/q/1 'f1)] | |
The first alternative looks the simplest to me. :) The extra BIND to one of F2's locals ('b) is necessary if CODE ever refers to any of F2's locals (B or CODE). (This avoids the next error message you were going to get. :) | |
Davide 15-Oct-2008 [11097] | double bind ! Thanks Anton, it works |
Geomol 15-Oct-2008 [11098] | Learn to bind knots with REBOL lecture one. ;) I always have trouble with BIND. Maybe I didn't ever take the time to really get it. So much to investigate with this language. :) |
amacleod 16-Oct-2008 [11099x2] | How do I convert: [{some sentence with some carriage returns and tabs}] to: [{some sentence with^/^-some carriage returns^/^-^-and tabs}] |
Is there a simple method or do I need to parse through and append each line while inserting the ^/ | |
Sunanda 16-Oct-2008 [11101] | This may have side effects, removing extra spaces: x: [{some sentence with { some carriage returns { and tabs}] >> trim first x == "some sentence with^/some carriage returns^/and tabs" |
Anton 16-Oct-2008 [11102] | Geomol, I was like that too, for quite some time, at the beginning. But... we can teach it to you !! It's really a simple concept. |
Geomol 16-Oct-2008 [11103] | I know the concept of a context. I actually use the word CONTEXT in most of my scripts. And reading the BIND help (with ? bind), I see, it binds words to a known word. So I guess, the known word is defining the context, the new words (1. argument of BIND) should bind to. But why, Anton, do you use two binds in your example? I would guess, something like: do bind [code b] h/q/1 should work? |
older newer | first last |